/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function BaseClass(extended_props){ this.extend = function(props){ for(var i in props){ this[i] = props[i] } } if(extended_props){ this.extend(extended_props); } if(this.init){ this.init(); } } var Foo = new BaseClass({ name: "Jamie Allison", init: function(){ alert("Called from Foo.init()"); } }); Foo.extend({ age: 32 }); alert("Age is: " + Foo.age);