Skip to content

Instantly share code, notes, and snippets.

@metasansana
Created July 2, 2013 20:21
Show Gist options
  • Save metasansana/5912763 to your computer and use it in GitHub Desktop.
Save metasansana/5912763 to your computer and use it in GitHub Desktop.
Parasitic inheritance and constructors without the new keyword in JavaScript.
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