我有一個javascript對象有多種方法。但是我注意到有關方法定義方式的一些不一致。Javascript方法定義不一致
這裏是對象:
function MenuObject(containerId, skin) {
this.id = containerId;
this.something = something2;
.
.
.
this.anotherThing = anotherThing2;
this.setSkin = function(skin) { //We have a function here
//body...
{
}
MenuObject.prototype.getTopLevelPolygon = function() //Another function.
{
var p = this.something3;
//Method body goes here...
}
一些的功能等this.functionName =函數(),其他類似MenuObject.prototype.functionName =函數()
定義我只是想知道爲什麼不屬於MenuObject定義爲MenuObject.prototype.functionName = function()的所有函數?
所以* real *問題是「爲什麼方法被添加到.prototype?」或者,也許,「原型'屬性是什麼?」或..提示:搜索「JavaScript原型」。 – 2013-03-23 00:36:56