Created
August 30, 2010 21:15
-
-
Save jboesch/558066 to your computer and use it in GitHub Desktop.
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
// This is just an example of a quick way of setting up a new instance with an automatic call to "init" | |
// | |
// Create our attachClass method | |
Object.prototype.attachClass = function(name, o){ | |
this[name] = function(){ | |
if(typeof(this.__init) == 'function'){ | |
this.__init.apply(this, arguments); | |
} | |
} | |
this[name].prototype = o; | |
} | |
// Declare our site object | |
var MySiteObj = {}; | |
MySiteObj.attachClass('Person', { | |
__init: function(o){ | |
alert("Hi, I'm " + o.age + " years old"); | |
this.sex = o.sex; | |
}, | |
getSex: function(){ | |
return this.sex; | |
} | |
}); | |
// Try it out! | |
var p = new MySiteObj.Person({ age: 15, sex: 'yes PLZ LOL ROFL!!!!' }); | |
alert(p.getSex()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment