javascript - Is it impossible to tell if a function is a generator function if .bind() has been called on it? -



javascript - Is it impossible to tell if a function is a generator function if .bind() has been called on it? -

looks calling .bind(this) on generator function breaks ability see if function generator. ideas on how prepare this?

var isgenerator = function(fn) { if(!fn) { homecoming false; } var isgenerator = false; // faster method first // calling .bind(this) causes fn.constructor.name 'function' if(fn.constructor.name === 'generatorfunction') { isgenerator = true; } // slower method sec // calling .bind(this) causes test fail else if(/^function\s*\*/.test(fn.tostring())) { isgenerator = true; } homecoming isgenerator; } var mygenerator = function*() { } var myboundgenerator = mygenerator.bind(this); isgenerator(myboundgenerator); // false, should true

since .bind() returns new (stub) function calls original .apply() in order attach proper this value, no longer generator , source of issue.

there solution in node module: https://www.npmjs.org/package/generator-bind.

you can either utilize module or see how solve (basically create new function .bind() returns generator).

javascript node.js generator ecmascript-harmony

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -