我感覺有點遺憾,但有些東西我不明白(甚至不知道是否有可能)關於JavaScript中的原型設計。
我想使用的方法,而我創造我的僞類的原型:參考創建原型時的方法
var Class = function() {}
Class.prototype = {
a: function() {
return 'ok'
}
, z: Class.prototype.a() // I tried with `this`/`constructor`/etc.
} // TypeError: Object [object Object] has no method 'a' the rest isn't evaluated
var test = new Class()
test.z
我知道我能做到這樣,但我想知道如果我能,但仍我在Class.prototype
聲明中的所有方法/屬性:
var Class = function() {}
Class.prototype.a = function() {
return 'ok'
}
Class.prototype.z = Class.prototype.a()
var test = new Class()
test.z // "ok"
謝謝。
無賴,但感謝。 – Calvein