What it the use of the Javascript constructor property?

Author Message

test123
Date sent: 2015/09/30 06:13:13
Trying to bend by head around Javascript's take on OO...and, like many others, running into confusion about the constructor property. In particular, the significance of the constructor property, as I can't seem to make it have any effect. E.g.:

test123
Date sent: 2015/09/30 06:13:28
function Foo(age) {
this.age = age;
}

function Bar() {
this.name = "baz";
}

Bar.prototype = new Foo(42);
var b = new Bar;

alert(b.constructor); // "Foo". That's OK because we inherit `Foo`'s prototype.
alert(b.name); // "baz". Shows that Bar() was called as constructor.
alert(b.age); // "42", inherited from `Foo`.
Copyright © 2013 by ustutorials. All Rights Reserved..