Created
April 18, 2013 12:39
-
-
Save roden0/5412415 to your computer and use it in GitHub Desktop.
JS object template. Author www.dustindiaz.com
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
| //SAMPLE OBJECT NOTATION | |
| var obj = { | |
| // string | |
| a : 'sampleValue', | |
| // array | |
| b : [obj1,obj2,'three',4,obj5], | |
| // function | |
| c : function() { | |
| var bang = this.a; | |
| } | |
| } | |
| //FUNCTIONS IN AN OBJECT | |
| var behavior = { | |
| a : '', | |
| b : null, | |
| c : Object, | |
| init : function() { | |
| // ... | |
| this.c = document.getElementById('c'); | |
| }, | |
| doThis : function() { | |
| // ... | |
| }, | |
| doThat : function() { | |
| // ... | |
| }, | |
| tweakThis : function() { | |
| // ... | |
| } | |
| } | |
| var behavior2 = { | |
| runThat : function() { | |
| // ... | |
| }, | |
| wrapThis : function() { | |
| // ... | |
| }, | |
| stringifyThat : function() { | |
| // ... | |
| }, | |
| calculateThis : function() { | |
| // ... | |
| } | |
| } | |
| //Object template | |
| var obj = { | |
| a : Object, | |
| b : Array, | |
| c : false, | |
| d : null, | |
| init : function() { | |
| // set local object vars here | |
| this.run(); | |
| }, | |
| run : function() { | |
| // run bulk of behavior here | |
| } | |
| } | |
| function initializer() { | |
| obj.init(); | |
| // other init() methods go here | |
| } | |
| addEvent(window,'load',inializer); //addEvent function required |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment