Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created December 6, 2008 09:54
Show Gist options
  • Save mkhl/32853 to your computer and use it in GitHub Desktop.
Save mkhl/32853 to your computer and use it in GitHub Desktop.
JavaScript
// A workaround for Javascript's bizarre constructor semantics
// Source: http://www.dekorte.com/blog/blog.cgi?do=item&id=3749
Object.clone = function() {
var constructor = new Function;
constructor.prototype = this;
obj = new constructor;
obj.init()
return obj
}
Object.init = function() {}
// Example:
View = Object.clone()
View.init = function() {
this.subviews = new Array
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment