var p = function () {
this.show = function () {
alert('hello world!!!');
}
}
p.prototype.show = function() {
alert('haha');
}
var o = new p();
o.show();
It alerts "hello world!!!", why?
Can I modify prototype method, if yes how?
That’s because the specific function you define in the constructor overrides the one that is inherited through the prototype.
From EcmaScript specification :
In short : when looking for a function (or any property by its name), you start at the object and then go up in the prototype chain.