improve javascript prototypal inheritance

Posted by Julio on Stack Overflow See other posts from Stack Overflow or by Julio
Published on 2010-06-11T16:44:24Z Indexed on 2010/06/11 16:52 UTC
Read the original article Hit count: 233

Filed under:
|
|

I'm using a classical javascript prototypal inheritance, like this:

function Foo() {}   
Naknek.prototype = {
//Do something
};
var Foo = window.Foo = new Foo();

I want to know how I can improve this and why I can't use this model:

var Foo = window.Foo = new function() {
};
Foo.prototype = {
//Do something
};

Why this code doesn't work? In my head this is more logical than the classical prototypal inheritance.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about inheritance