New and Prototype in Javascript

,

First . Please look at any code below .

var foo = function(name){
this.name = name || ‘Untitled’;
}
foo.prototype = {
getName : function(){
return this.name;
}
}

var Foo = new foo(‘dog’);
console.log( Foo.getName() ); // ‘dog’ #1

foo.prototype = {
     getName : function(){
        return 're Prototype : ' + this.name;
     }
}

console.log( Foo.getName() ); // 'dog' #2

var Foo2 = new foo(‘pig’);

console.log( Foo.getName() ); // 're Prototype: pig' #3

###Conclusion .

Function’s prototype object had confirmed before “new” operating . So the Object prototype chain ‘proto‘ had the reference to the object when Function prototype attribute had settled .

#3 result . Change Function’s Prototype reference & “new” again . The result object’s prototype chain could get the lastest chain .