0
如果我有:調用函數範圍之謎
Object._extends = function(Derived, Base)
{
Derived.prototype = new Base();
Derived.prototype.constructor = Derived;
Derived.uber = Derived.prototype;
}
var BASE = function()
{
this._name = "BASE"
}
var DERIVED = function()
{
Object._extends(DERIVED, BASE)
this._age = 3;
}
// Object._extends(DERIVED, BASE) if I write here all is ok!!!
alert(new DERIVED()._name) // undefined!
當我寫Object._extends(DERIVED, BASE)
到DERIVED
功能則_name
是不確定的,但如果我寫相同的功能出來那麼它是不是不確定的,但爲什麼呢?
嘗試'Object._extends(this,BASE)' – jantimon 2009-10-13 11:43:38
我不能用'this',因爲我必須設置prototype屬性,它是函數DERIVED的一個屬性 – xdevel2000 2009-10-13 13:01:45