在javascript函数上调用.bind()
时,堆栈跟踪会发生什么?
例如,当我有
时Function.prototype.arg = function() {
var fn = this;
return function augmented(){
// do something with the arguments
fn.apply(c, args); // and call it
};
}
并在函数
上使用它(function x(){console.trace();}).arg()()
它会记录
x
augmented
<global context>
那么bind()做什么(内部)?它也可以像arg()那样执行部分应用程序和集合上下文操作,正如您在各种填充程序中看到的那样(例如。MDC's compatibility函数)。
我从ecmascript规范中知道它将创建一个新函数,并设置它的内部属性来存储上下文和参数,但它仍然只是一个指向原始函数的指针(你可以看到原型) 。然而,
(function x(){console.trace();}).bind()()
只会记录
x
<global context>
内部是否真的没有额外的调用,或者只是在trace-method中隐藏了什么?