I cannot understand why the constructor property is what is in JS. Sometimes I find myself using it to get to prototype objects (for example, an Event object) in IE <9. However, I think this allows some programmers to manipulate the classic OO programming constructs:
function Foo() { this.name = 'Foo'; } function Bar() { this.name = 'Bar'; } function Foobar(){}; Foo.prototype = new Foobar; Foo.prototype.constructor = Foo; Bar.prototype = new Foobar; Bar.prototype.constructor = Bar; var foo = new Foo(); var bar = new Bar();
So, AFAIK, the "advantages" of a constructor property:
- easy to instantiate objects from an instance
- the ability to group your objects as subclasses of a particular class, but still be able to check what type of subclass you are dealing with.
- As you say: be careful.
source share