Created
July 2, 2013 20:21
-
-
Save metasansana/5912763 to your computer and use it in GitHub Desktop.
Parasitic inheritance and constructors without the new keyword in JavaScript.
This file contains 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
var ns= {}; | |
ns.Object = function () { | |
var that = {}; | |
that.toString = function () { | |
return 'I am an Object!!'; | |
} | |
return that; //return an object with a method called toString() | |
} | |
ns.UselessObject = function() { | |
var that = ns.Object(); //gets the return value of calling the ns,Object function. | |
that.toString = function () { | |
return 'I am useless!' | |
} | |
return that; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment