【发布时间】:2014-03-01 07:27:31
【问题描述】:
我根据来自对象someObject 的someFunction 定义了一个名为anotherObject 的对象和一个名为anotherFunction 的函数。
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 未定义。
【问题讨论】:
-
(function(){})==(function(){})
-
anotherObject[anotherFunction]()是垃圾 -
你的问题到底是什么?
-
如何将一个对象中的函数复制到另一个对象?
标签: javascript function object