Click to See Complete Forum and Search --> : changing default constructor


aQuos
05-05-2007, 08:03 AM
I have this:

function foo() {
alert( 'default constructor' ) ;
// methods and properties
}

function bar() {
alert( 'new constructor' ) ;
}

foo.prototype.constructor = bar ;

new foo() ;

I wanna change the default constructor with new constructor, leaving all foo's methods and properties unchanged, but when create a new instance of foo, still alert 'default constructor'... what's wrong?

Beanis
05-05-2007, 06:29 PM
Maybe:

foo.prototype.constructor = bar();

aQuos
05-06-2007, 06:28 AM
no... bar() executes the funcion bar