co icon indicating copy to clipboard operation
co copied to clipboard

there is something unsuitable about isGenerator and isObject function

Open waterVenice7 opened this issue 8 years ago • 2 comments
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;

waterVenice7 avatar Mar 03 '17 01:03 waterVenice7

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

jsdevtom avatar Jan 14 '20 05:01 jsdevtom

Please label as Bug

jsdevtom avatar Jan 14 '20 05:01 jsdevtom