this keyword in javascript

This page neatly explains about “this” keyword
http://www.quirksmode.org/js/this.html

From javascript object oriented programming concepts – http://www.sitepoint.com/oriented-programming-1-2/

The this keyword inside a constructor function refers to the object that’s being created.

Quoting below example from SitePoint.com

function myFunc(StringValue){  <br>
this.StringValue = StringValue;  <br>
}  <br>
<br>
var myObject = new myFunc("This is myObject's string");  <br>
var myObject2 = new myFunc("This is a String");  <br>
alert(myObject.StringValue); // displays "This is myObject's string"  <br>
alert(myObject2.StringValue); // displays "This is a String"

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: