我使用anotherFunction
函數基於來自對象someObject
的someFunction
定義了一個名爲anotherObject
的對象。基於另一個對象的屬性定義對象的屬性
var someObject={
someFunction:function(){
return this;
}
};
console.log(someObject.someFunction()===someObject);//true
var someFunc=someObject.someFunction;
console.log(someFunc===someObject.someFunction);//true
//the function does not have the same context as that of the function called earlier...
console.log(someFunc()===someObject);//false
var anotherObject={
anotherFunction:someObject.someFunction
};
console.log(anotherObject.anotherFunction===someObject.someFunction);//true
console.log(anotherObject[anotherFunction]()===anotherObject);//true;
console.log(anotherObject.anotherFunction()===someObject);//false
Firefox Scratchpad報告未定義功能anotherFunction
。
(函數(){})==(函數(){}) – bjb568
'anotherObject [anotherFunction] ()'是垃圾 – Bergi
你的問題到底是什麼? – Bergi