Skip navigation

To understand the  constructor, consider the following code

// constructor function definition
function sum(a,b){; = a + b;

// create object using sum constructor
var sal = new sum(3,3);

alert(;  // 6
alert(sal.constructor)  // displays function definition above

Now sal is object of type sum.

Interesting part is you can create sum object using sal though constructor property. Here is how…

var sal1 = new sal.constructor(5,5);
alert(;  // 10

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: