-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Certain specified behaviours of native constructors can't be simulated, such as setting the [[Class]] and [[PrimitiveValue]] properties. This prevents us from constructing an instance of these constructors with a nondeterministic number of arguments (as you would with apply normally). Here's how we can try to instantiate Date the way we would any other constructor with a dynamic set of arguments:
+function(ctor, args){
var tmpCtor = function(){};
tmpCtor.prototype = ctor.prototype;
var obj = new tmpCtor;
var result = ctor.apply(obj, args)
return Object(result) === result ? result : obj;
}(Date, [1990, 01, 01]);You would expect this to produce 633852000000, but because it doesn't have a [[PrimitiveValue]], it throws the error
TypeError: this is not a Date object.
at Date.valueOf (native)
[...]
Metadata
Metadata
Assignees
Labels
No labels