我在Nodejs v0.11.2中使用了生成器,我想知道如何检查我的函数的参数是生成器函数.
我找到了这种方式,typeof f === 'function' && Object.getPrototypeOf(f) !== Object.getPrototypeOf(Function)但我不确定这是否好(并在将来工作)方式.
你对这个问题有什么看法?
如何使用它的参考来区分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?