Created
May 19, 2011 14:54
-
-
Save kaaes/980930 to your computer and use it in GitHub Desktop.
Example of that/self workaround
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); | |
function clickCallback(evt) { | |
// 'this' is an object on which we call the function | |
// 'that' is always the reference to prototype object | |
// log id of the HTML element | |
console.log('HTML id -> ' + this.id); | |
// log id we've given to the JS object ('JSnode_HTMLid') | |
console.log('JS id -> ' + that.id); | |
// log time of creation | |
console.log('created at -> ' + that.createdAt); | |
} | |
} | |
var divEl = new JSobj('cont'); | |
// it will log: | |
// HTML id -> cont | |
// JS id -> JSnode_cont | |
// created at -> 331305814994963 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment