Created
December 6, 2008 09:54
-
-
Save mkhl/32853 to your computer and use it in GitHub Desktop.
JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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