是否可以界定母职职能的范围,并将通过母职职能通过的论点作为其范围加以约束,然后再将其退回?
例如:
var myObject = {
foo: "bar"
};
var myFunction = (function() {
return function() {
return this.foo;
};
}).call(myObject);
myFunction.call(myObject); // I d like to bind myObject as this does ...
myFunction(); // ... but I d like to do it before invoking it, without .call() or .apply()
或者另一个复杂的例子,它描述了我试图做些什么:
var createMyCopy = function(original, self) {
var copy;
eval("copy=" + original.toString());
console.log(copy()); // returns undefined
};
(function() {
var self = "Hello world",
myFunction = function() {
return self;
};
console.log(myFunction()); // returns "Hello world"
createMyCopy(myFunction);
})();
我试图制作一份功能的复印件,以便我能够在不改动原有功能的情况下对功能作出改动,但我想有原功能中定义的变量。