Closed jasnell closed 7 years ago
For natives (built-ins), will there still be a way to distinguish between a constructor and a function ?
@doodadjs ... just so I'm clear, are you referring to the difference between new Foo()
and Foo()
?
Between "new Object()" and Object.hasOwnProperty()
"is constructor" is a very different type of check than this proposal provides; and you can kind of do that now with something like function hasConstructSlot(x) try { new Proxy(x, { construct() {} }); return true; } catch (e) { return false; } }
.
I'm talking about natives. But ok.
@doodadjs ok... yeah I get where you're going, but as @ljharb points out that's a very different kind of check. I do think it would be valuable for a function to indicate via a property if it's a constructor or not, but I'd prefer to handle that separately.
@ljharb ... the original question still stands here... should Builtin.is()
work for builtin functions and methods also?
Yes, I think so.
@ljharb @bengl: Should built-in functions and methods also be supported by this? For instance,
This can be accomplished by requiring that such built-in functions be given a
[[Builtin]]
internal slot and a@@builtin
own property of their own.Note that passing the builtin function and method to
Builtin.typeof()
(e.g.Builtin.typeof(parseInt)
) would still just return'function'
.