相关疑难解决方法(0)

检查功能是否是发电机

我在Nodejs v0.11.2中使用了生成器,我想知道如何检查我的函数的参数是生成器函数.

我找到了这种方式,typeof f === 'function' && Object.getPrototypeOf(f) !== Object.getPrototypeOf(Function)但我不确定这是否好(并在将来工作)方式.

你对这个问题有什么看法?

javascript yield generator ecmascript-6

54
推荐指数
7
解决办法
1万
查看次数

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

如何使用它的参考来区分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
查看次数