co
co copied to clipboard
there is something unsuitable about isGenerator and isObject function
trafficstars
function isGenerator(obj) {
return 'function' == typeof obj.next && 'function' == typeof obj.throw;
}
why not use toString.call(obj)==="[object Generator]" to replace that? I think this is a more definite judge solution than default way;
function isObject(val) {
return Object == val.constructor;
}
val.constrctor could be rewrited, I suggest that we can use toString.call(val)==="[object Object]" to get a more explicit check;
When yielding {} in a generator, I get this message because the isObject function isn't more robust
TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "[object Object]"
isObject, according to the most upvoted stackoverflow post should be:
return typeof yourVariable === 'object' && yourVariable !== null
Please label as Bug