Skip to content

Instantly share code, notes, and snippets.

@faustman
Created July 25, 2013 13:53
Show Gist options
  • Save faustman/6079863 to your computer and use it in GitHub Desktop.
Save faustman/6079863 to your computer and use it in GitHub Desktop.
Function Call Stack GA Style
var Hello = function(argv){
if(argv instanceof Array){
while(f = argv.shift()) {
this.push(f);
}
}
return this;
}
Hello.prototype = {
color: 'black',
_setColor: function(color){
this.color = color;
},
_sayHello: function(el){
var e = document.getElementById(el) || this.crateEl();
e.innerText = "HELLO!";
e.style.color = this.color;
},
push: function(arr){
if(!arr) return false;
// Some triggers
f_name = arr.shift();
console.log("Invoke function: " + f_name, arr)
this[f_name].apply(this, arr); // Need some validation.
return true;
},
createEl: function(){
var el = document.createElement('div');
document.body.insertBefore(el);
return el;
}
}
document.body.addEventListener('load', function(){
console.log("Before load", _q);
var _q = new Hello(_q);
console.log("After load", _q);
})
<script>
var _q = _q || [];
_q.push(["_setColor", "red"]);
_q.push(["_sayHello"])
</script>
<script src="hello.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment