浅谈JS中几种轻松处理’this’指向方式
我喜欢在JS中更改函数执行上下文的指向,也称为 this 指向。 例如,咱们可以在类数组对象上使用数组方法: const reduce = Array.prototype.reduce; function sumArgs() { return reduce.call(arguments, (sum, value) => { return sum += value; }); } sumArgs(1, 2, 3); // => 6 另一方面,this 很难把握。 咱们经常会发现自己用的 this 指向不正确。下面的教你如何简单地将 this 绑定到所需的值。 在开始之前,我需要一个辅助