【发布时间】:2018-10-17 14:23:06
【问题描述】:
我正在尝试使用箭头方法访问嵌套函数中的组件 this。当我使用箭头方法时,我得到一个编译器错误“错误 TS2496:在 ES3 和 ES5 的箭头函数中无法引用 'arguments' 对象。考虑使用标准函数表达式。”
我读过它并试图将其转换为休息参数,但不知道如何让它工作。
休息前参数:
((H => {
H.wrap((H as any).seriesTypes.sunburst.prototype, 'drillUp', (proceed) => {
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
console.log('drillup');
this.drillUpClick();
});
}))(Highcharts);
休息后参数:
((H => {
H.wrap((H as any).seriesTypes.sunburst.prototype, 'drillUp', (proceed, ...args) => {
proceed.apply(this, Array.prototype.slice.call(args, 1));
console.log('drillup');
this.drillUpClick();
});
}))(Highcharts);
我无法启动 console.log。收到错误“无法读取未定义的未定义属性”
请指教。
【问题讨论】:
-
proceed.apply(this, args); -
不。没用。还是一样的错误。
-
不,但现在可能正在对
this唠叨,箭头功能也没有。并且没有其他选择。你需要使用普通的function(proceed, ...args){ proceed.apply(this, args); ... } -
听起来像这样。现在向上钻取功能停止工作。
-
向我们展示对
drillUp函数的调用
标签: javascript angular ecmascript-6