Created
July 25, 2013 13:53
-
-
Save faustman/6079863 to your computer and use it in GitHub Desktop.
Function Call Stack GA Style
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
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); | |
}) |
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
<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