jasnell / proposal-istypes

TC-39 Proposal for additional is{Type} APIs
201 stars 7 forks source link

Builtins.[typeof|is] clarifications #21

Closed bengl closed 7 years ago

bengl commented 7 years ago

What would the following return, assuming Builtins.is(Foo) === true and Foo is some constructor?

jasnell commented 7 years ago

Builtins.typeof(Foo) === 'object' .. because Foo itself is not an instance of a built-in (not counting 'Object') Builtins.typeof(Foo.prototype) === 'object' ... same reason Builtins.is(Foo.prototype) === true Builtins.is(Foo.bar) ... depends on the assigned value of bar. If the assigned value is a built-in, then Builtins.is(Foo.bar) === true

jasnell commented 7 years ago

Note, We would need to decide if Builtins.is(undefined) returns true or false. I don't have a great answer for that yet.

doodadjs commented 7 years ago

"undefined" has no constructor, so I'll say "false".

bengl commented 7 years ago

Builtins.typeof(Foo) === 'object' .. because Foo itself is not an instance of a built-in (not counting 'Object')

Foo is a constructor, so 'function', right?

Builtins.is(Foo.prototype) === true

Hmm, I would have thought false, for the same reason as Foo.bar, also noting the Date example:

const m = {};
Object.setPrototypeOf(m, Date);     // note that this isn't setting it to Date.prototype
Builtins.is(m);                                  // true
jasnell commented 7 years ago

Yeah that makes sense re Builtins.is(Foo.prototype) ... it really depends on what the assigned value is

jasnell commented 7 years ago

Oh.. and yes, sorry, assuming Foo is a constructor, Builtins.typeof(Foo) would be function

jasnell commented 7 years ago

Closing as answered