Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created July 15, 2009 22:55
Show Gist options
  • Select an option

  • Save jaredatron/148042 to your computer and use it in GitHub Desktop.

Select an option

Save jaredatron/148042 to your computer and use it in GitHub Desktop.
Class.apply = function apply(klass, a){
return eval(
'new klass('+
a.map(function(v,i){ return 'a['+i+']'; }).join(',')+
')'
);
}
new Array([1,2,4,8]);
// => [[1,2,4,8]]
Class.apply(Array,[1,2,4,8]);
// => [1,2,4,8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment