Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
Forked from jed/newOperator.js
Created November 28, 2011 13:32
Show Gist options
  • Save DavidBruant/1400408 to your computer and use it in GitHub Desktop.
Save DavidBruant/1400408 to your computer and use it in GitHub Desktop.
an attempt to make the new operator dynamically invokeable
// Requires a native Function.prototype.bind (IE9+, FF4+, Chrome, Opera 12, no Safari)
function newOperator(constructor, args) {
var params = [undefined].concat(args)
var cst = Function.prototype.bind.apply(constructor, params);
return new cst();
}
@jed
Copy link

jed commented Nov 28, 2011

oh, nice. this works:

(new (Function.prototype.bind.apply(Date, [1995, 11, 24]))).toUTCString()

if only it were cross-platform...

@tsaniel
Copy link

tsaniel commented Dec 2, 2011

It should be

(new (Function.prototype.bind.apply(Date, [window, 1995, 11, 24]))).toUTCString()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment