With proxies, a program can test whether an object has [[Construct]] or not.
function hasConstruct(f) {
var p = new Proxy(f, {construct: () => { throw true }});
try {
new p; // handler.construct hook fires iff f has [[Construct]]
} catch (exc) {
return exc === true;
}
}
hasConstruct(function () {}); // true
hasConstruct(a => a); // false (true in Firefox, a bug)
hasConstruct(Math.sin); // false (true in Firefox, a bug)
The way the spec is currently written, *all* bound functions have [[Construct]].
hasConstruct(function () {}.bind()); // true
hasConstruct((a => a).bind()); // true (I propose making it false)
hasConstruct(Math.sin.bind()); // true (I propose making it false)
I think it's more sensible for a bound function to be a constructor only if the target function is.
fixed in rev16 editor's draft
fixed in rev16 draft. July 15, 2013