如何使用它的参考来区分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?
我有一个接受回调并绑定this到它的函数。如果使用箭头函数作为回调调用该函数,我想抛出错误(因为我无法绑定this到箭头函数)。
就像是:
doSomethingWithMyCallback(function(){}); // ok
doSomethingWithMyCallback(() => {}); // should throw an error
Run Code Online (Sandbox Code Playgroud)
如何检查回调是否不是箭头函数(即我可以绑定this到它)?