Function.prototype.call和Function.protoype.all只应用一个参数
Function.prototype.call and Function.prototype.apply with only one argument
Function.prototype.call或Function.prototype.apply只使用一个参数做什么?
这是怎么回事?
Function.prototype.myBind = function (context) {
var fun = this;
return function(){
return fun.call(context);
}
}
它在不传递任何参数的情况下调用函数。
fun.call(context)
CCD_ 1中的函数将使用CCD_。
这基本上相当于调用:
context.temp = fun;
context.temp();
当然对于CCD_ 3,将不添加额外的属性。
这里有一个例子:
var a = {foo: 'bar'},
b = {foo: 'baz'};
function example() {
console.log(this.foo);
}
console.log('example called on a');
example.call(a); //'bar'
console.log('example called on b');
example.call(b); //'baz'
*this
在函数内
相关文章:
- 如何通过 Function.prototype.apply() 更改调用函数的参数
- Function.prototype.call和Function.protoype.all只应用一个参数
- Function.prototype.apply:参数列表的类型错误
- “function(){ 返回这个 }()” 作为参数做什么
- 使用 Function.prototype.bind.apply(Obj, args) 将参数传递给对象,只传递第一个元
- Function.prototype.bind with null 作为参数
- 如何将参数传递到 Highcharts-Function
- 向使用javascript中的new function关键字创建的函数传递参数
- 在没有上下文参数的情况下调用本机绑定函数(function.prototype.bind)
- Javascript参数化字符串:replace(RegExp, function)意外分组/匹配
- args.slice(1)如何分离传递给PhantomJS和forEach(function(arg, i)的参数…功能
- 将function作为参数传递给function时调用private function
- 为什么将jQuery作为参数传递给(function($){.})(jQuery)闭包包装器,而不是本地变量?
- 我如何在this.function.bind(this)中替换任何数值作为参数
- 在jquery事件中,为什么我们将function()作为参数传递
- 将参数附加到Javascript函数,而不是前置(Function.protype.bind)
- 像这样更改参数[function.value(new value)]
- 将参数传递给 a4j:function
- 将function.prototype.call生成的函数作为参数传递时,Array.prototype.map不是函数
- 需要帮助将function作为第一个参数的函数调用转换为CoffeeScript