function apply(func, thisArg, args) { case 0: return func.call(thisArg); case 2: return func.call(thisArg, args[0],args[1]);
case 3: return func.call(thisArg, args[0], a
在JS手册中,我有以下示例,它工作正常: someMethod() { },
alert("Called); if (cache.has(x)) { }
let result = func.call我将讨论cachingDecorator中的这一行:let result = func.call(this, x)
我知道,如果你有一些javascript函数,并且你想调用它,这样在其中使用this将不会引用直接调用它的对象,你可以使用func.call(thatObject,param,and,more,params但是假设你是func的作者,func的唯一用法是通过func.call,function func(that,param,and,more,params...) {//and in here use *that* and not *this*是的,它看起来不那么“酷”,因为它不是一个对象的方法,但是