相关疑难解决方法(0)

如何区分箭头函数,类和正常函数?

如何使用它的参考来区分ES6中的这三个东西?

let x = i => i+1;

class y { constructor(i) { this._i=i+1; } get i(){ return this._i;} }

function z(i) { return i+1; }
Run Code Online (Sandbox Code Playgroud)

例:

test(x) //=> 'arrow'
test(y) //=> 'class'
test(z) //=> 'function'
Run Code Online (Sandbox Code Playgroud)

我怎样才能在转录器中区分这些东西 - Traceur/Babel?

javascript ecmascript-6 arrow-functions

4
推荐指数
1
解决办法
161
查看次数

如何正确检查回调是否是箭头函数?

我有一个接受回调并绑定this到它的函数。如果使用箭头函数作为回调调用该函数,我想抛出错误(因为我无法绑定this到箭头函数)。

就像是:

doSomethingWithMyCallback(function(){}); // ok
doSomethingWithMyCallback(() => {}); // should throw an error
Run Code Online (Sandbox Code Playgroud)

如何检查回调是否不是箭头函数(即我可以绑定this到它)?

javascript

-1
推荐指数
1
解决办法
1138
查看次数

标签 统计

javascript ×2

arrow-functions ×1

ecmascript-6 ×1