Skip to content

Instantly share code, notes, and snippets.

@roden0
Created April 18, 2013 12:39
Show Gist options
  • Save roden0/5412415 to your computer and use it in GitHub Desktop.
Save roden0/5412415 to your computer and use it in GitHub Desktop.
JS object template. Author www.dustindiaz.com
//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