It seems that calling .bind (this) on any generator function violates my ability to see if this function is a generator. Any ideas on how to fix this?
var isGenerator = function(fn) { if(!fn) { return false; } var isGenerator = false; // Faster method first // Calling .bind(this) causes fn.constructor.name to be 'Function' if(fn.constructor.name === 'GeneratorFunction') { isGenerator = true; } // Slower method second // Calling .bind(this) causes this test to fail else if(/^function\s*\*/.test(fn.toString())) { isGenerator = true; } return isGenerator; } var myGenerator = function*() { } var myBoundGenerator = myGenerator.bind(this); isGenerator(myBoundGenerator); // false, should be true
Kirk Ouimet Nov 06 '14 at 0:11 2014-11-06 00:11
source share