https://tc39.github.io/ecma262/#sec-function.prototype.bind

当我阅读“ NOTE 1 NOTE 2”时,我听不懂吗?


注1


使用Function.prototype.bind创建的功能对象是奇异对象。它们也没有原型属性。


笔记2


如果Target是箭头函数或绑定函数,则随后的F调用将不使用传递给此方法的thisArg。

有人可以举一些例子吗?

最佳答案

关于注1:

const bound = (function(){}).bind();
console.log(bound instanceof Function);
console.log(!("prototype" in bound));
// being an "exotic object" just means that it behaves unusual - in this case,
// having a special [[call]] operation


关于注2:

function example() { "use strict"; console.log(this); }
const bound = example.bind("Hello");
const boundAgain = bound.bind("World");
console.log(bound(), boundAgain()); // Hello Hello

function makeArrow() { "use strict"; return () => console.log(this); }
const arrow = makeArrow.call("Hello");
const boundArrow = bound.bind("World");
console.log(arrow(), boundArrow()); // Hello Hello

关于javascript - 使用Function.prototype.bind创建的函数对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53883866/

10-09 09:54