<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.toString() &#187; Javascript</title>
	<atom:link href="http://www.dottostring.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dottostring.com</link>
	<description>Programming is our passion</description>
	<lastBuildDate>Sun, 04 Oct 2009 15:57:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to use prototype to add Properties/Methods to a class in Javascript</title>
		<link>http://www.dottostring.com/2008/11/how-to-use-prototype-to-add-propertiesmethods-to-a-class-in-javascript/</link>
		<comments>http://www.dottostring.com/2008/11/how-to-use-prototype-to-add-propertiesmethods-to-a-class-in-javascript/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 20:30:26 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=88</guid>
		<description><![CDATA[I discussed the basics of Object Oriented Javascript Programming in my previous post. Now lets extend a class to add some more properties and methods to its definition. 
Every object constructor has a special property &#8216;prototype&#8217; in Javascript (Please do not confuse it with prototype javascript library). Lets use it:

function myClass() {
}
myClass.prototype.aProperty = "foo";
var myObject = [...]]]></description>
			<content:encoded><![CDATA[<p>I discussed the <a title="Basics of Object Oriented Programming in Javascript" href="/2008/11/basics-of-object-oriented-programming-in-javascript/">basics of Object Oriented Javascript Programming</a> in my previous post. Now lets extend a class to add some more properties and methods to its definition. </p>
<p>Every object constructor has a special property <em>&#8216;prototype&#8217;</em> in Javascript (Please do not confuse it with <a href="http://www.prototypejs.org/" target="_blank">prototype javascript library</a>). Lets use it:</p>
<pre name="code" class="js">
function myClass() {
}
myClass.prototype.aProperty = "foo";
var myObject = new myClass();
alert(myObject.aProperty);
</pre>
<p>This adds aProperty to the definition of myClass. The <em>&#8216;prototype&#8217;</em> adds this property to all the objects whether they have been created or not. So, this example will work too:</p>
<pre name="code" class="js">
function myClass() {
}
var myObject = new myClass();
myClass.prototype.aProperty = "foo";
alert(myObject.aProperty);
</pre>
<p>The <em>&#8216;prototype&#8217;</em> object loads before the object&#8217;s constructor does anything.</p>
<pre name="code" class="js">
function myClass() {
	this.aProperty = "bar";
}
var myObject = new myClass();
myClass.prototype.aProperty = "foo";
alert(myObject.aProperty);
// this alert will show "bar"
</pre>
<p>So, using <em>&#8216;prototype&#8217;</em> we cannot override the properties and methods already defined in the object&#8217;s constructor.</p>
<p>We can use the <em>&#8216;prototype&#8217;</em> to add functionalities to the already existing classes. Lets add some functionality to the String class.</p>
<pre name="code" class="js">
String.prototype.vowelLength = function() {
	var count = 0;
	for(i=0; i &lt; this.length; i++) {
		var l = this.charAt(i); 
		if(l == "a" || l == "A" || l == "e" || l == "E" || l == "i" || l == "I" || l == "o" || l == "O" || l == "u" || l == "U") {
			count++;
		}
	}
	return count;
}
var myString = "United States of America";
alert(myString.vowelLength());
</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F11%2Fhow-to-use-prototype-to-add-propertiesmethods-to-a-class-in-javascript%2F';
  addthis_title  = 'How+to+use+prototype+to+add+Properties%2FMethods+to+a+class+in+Javascript';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/11/how-to-use-prototype-to-add-propertiesmethods-to-a-class-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basics of Object Oriented Programming in Javascript</title>
		<link>http://www.dottostring.com/2008/11/basics-of-object-oriented-programming-in-javascript/</link>
		<comments>http://www.dottostring.com/2008/11/basics-of-object-oriented-programming-in-javascript/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 20:42:23 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=83</guid>
		<description><![CDATA[Javascript is very powerful prototype based language. Although it is not a full blown OOP language like Java but it is an object based language. 
Lets start Object Oriented Programming in Javascript
Simplest class:

function myFirstClass() {
}

var myObject = new myFirstClass();
myObject.someProperty = "This is value 1";
alert(myObject.someProperty);

We can create another instance of myFirstClass like this:

var anotherObject = new myFirstClass();
anotherObject.someProperty [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript is very powerful prototype based language. Although it is not a full blown OOP language like Java but it is an object based language. </p>
<p>Lets start Object Oriented Programming in Javascript</p>
<p>Simplest class:</p>
<pre name="code" class="js">
function myFirstClass() {
}

var myObject = new myFirstClass();
myObject.someProperty = "This is value 1";
alert(myObject.someProperty);
</pre>
<p>We can create another instance of myFirstClass like this:</p>
<pre name="code" class="js">
var anotherObject = new myFirstClass();
anotherObject.someProperty = "This is property of another class";
</pre>
<p>Lets take the property to the definition of our class</p>
<pre name="code" class="js">
function myFirstClass(property1) {
	this.someProperty = property1;
}

var myObject = new myFirstClass("Hello World!");
alert(myObject.someProperty);
</pre>
<p>Now we will introduce some methods of our class</p>
<pre name="code" class="js">
function method1_myFirstClass() {
	alert("This is method 1 of my first class");
}

function myFirstClass(property1) {
	this.someProperty = property1;
	this.method1 = method1_myFirstClass;
}

var myObject = new myFirstClass("Hello World!");
myObject.method1();
</pre>
<p>Now we will write it within our class definition</p>
<pre name="code" class="js">
function myFirstClass(property1) {
	this.someProperty = property1;
	this.method1 = function() {
		alert("This is method 1 of my first class");
	};
}

var myObject = new myFirstClass("Hello World!");
myObject.method1();
</pre>
<p>Now we have seen a new way of writing functions. Why not write our class in this way too.</p>
<pre name="code" class="js">
var myFirstClass = function(property1) {
	this.someProperty = property1;
	this.method1 = function() {
		alert("This is method 1 of my first class");
	};
}

var myObject = new myFirstClass("Hello World!");
myObject.method1();
</pre>
<p>I will share advanced features related to OOP javascript in my coming posts. </p>
<p>Stay tuned!</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F11%2Fbasics-of-object-oriented-programming-in-javascript%2F';
  addthis_title  = 'Basics+of+Object+Oriented+Programming+in+Javascript';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/11/basics-of-object-oriented-programming-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to namespace your Javascript</title>
		<link>http://www.dottostring.com/2008/11/how-to-namespace-your-javascript/</link>
		<comments>http://www.dottostring.com/2008/11/how-to-namespace-your-javascript/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 18:38:39 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[namespace]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=39</guid>
		<description><![CDATA[Put everything in a namespace. This not only avoids collisions with other people&#8217;s scripts but also organize your objects into groups that make sense. Lets start namespacing !
// Using abbreviation of DotToString = DTS
if (typeof DTS == "undefined")
{
	var DTS = {};
}
// Make a function for creating namespaces
DTS.namespace = function() {
	var a=arguments, o=null, i, j, d;
	for [...]]]></description>
			<content:encoded><![CDATA[<p>Put everything in a namespace. This not only avoids collisions with other people&#8217;s scripts but also organize your objects into groups that make sense. Lets start namespacing !</p>
<pre name="code" class="js">// Using abbreviation of DotToString = DTS
if (typeof DTS == "undefined")
{
	var DTS = {};
}</pre>
<pre name="code" class="javascript">// Make a function for creating namespaces
DTS.namespace = function() {
	var a=arguments, o=null, i, j, d;
	for (i=0; i&lt;a.length; i=i+1) {
		d=a[i].split(".");
		o=DTS;

		// DTS is implied, so it is ignored if it is included
		for (j=(d[0] == "DTS") ? 1 : 0; j&lt;d.length; j=j+1) {
			o[d[j]]=o[d[j]] || {};
			o=o[d[j]];
		}
	}

	return o;
};</pre>
<p>and thats all <img src='http://www.dottostring.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Now you can create your own namespaces like this:</p>
<pre name="code" class="javascript">// We can mention our top level namespace
DTS.namespace("DTS.UI.Example");</pre>
<pre name="code" class="javascript">// or we can just skip top level namespace
DTS.namespace("UI.widgets");</pre>
<pre name="code" class="javascript">// or we can have a hybrid case
DTS.namespace("DTS.UI.Example", "UI.widgets");
</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F11%2Fhow-to-namespace-your-javascript%2F';
  addthis_title  = 'How+to+namespace+your+Javascript';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/11/how-to-namespace-your-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
