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
var el = document.getElementById('showCounterTrigger'); | |
el.onclick = function(evt) { logger.getCounter() } | |
// if you're operating in ECMA5 environment (webkit or gecko) | |
// you can also use bind() (more about bind below) | |
el.onclick = logger.getCounter.bind(logger); | |
// just remember that every event callback has an event object | |
// passed as a first parameter, so be careful when reusing methods |
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
var el = document.getElementById('showCounterTrigger'); | |
el.onclick = logger.getCounter |
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
// create Logger constructor with few properties | |
var Logger = function(id) { | |
this.container = document.getElementById(id); | |
this.counter = 0; | |
} | |
// add functionalities with prototype | |
Logger.prototype.log = function(msg) { | |
this.container.innerHTML = msg ; | |
this.counter++; |
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
var a, b, c, d, e; | |
a = function(obj) { | |
return this; | |
} | |
// when you call the function in 'function form' 'this' is window object | |
a(); // window |
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
function sum () { | |
var s = 0; | |
for (var i = 0, len = arguments. length; i < len; i++) { | |
s += arguments[i]; | |
} | |
return s; | |
} | |
// execute function and | |
// return 6, context is window |
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
var JSobj = function(id) { | |
var that = this; | |
var date = new Date(); | |
that.id = 'JSnode_' + id; | |
that.element = document.getElementById(id); | |
that.createdAt = date.getTime(); | |
that.element.addEventListener('click', clickCallback, false); |
NewerOlder