Skip to content

Instantly share code, notes, and snippets.

@ryuone
Created February 9, 2011 00:50
Show Gist options
  • Save ryuone/817647 to your computer and use it in GitHub Desktop.
Save ryuone/817647 to your computer and use it in GitHub Desktop.
JavaScript new Method like Ruby
Function.prototype.new = function(){
return new this;
}
function Super(){
this.ver='Super 0.1';
return this;
}
Super.prototype.now = function(){
return (new Date()).getTime();
}
function Sub(){
this.ver='Sub 0.1';
return this;
}
Sub.prototype = Super.prototype;
Sub.prototype.constructor = Sub
var subobj = Sub.new()
subobj.ver // "Sub 0.1"
subobj.now() // 1297212630859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment