Skip to content

Instantly share code, notes, and snippets.

@kaaes
Created May 19, 2011 15:06
Show Gist options
  • Save kaaes/980967 to your computer and use it in GitHub Desktop.
Save kaaes/980967 to your computer and use it in GitHub Desktop.
Watch out for context part 1
// 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++;
}
Logger.prototype.getCounter = function() {
this.log(this.counter);
}
// create new logger object and log few messages
var logger = new Logger('logger');
logger.log('wow');
logger.log('plum');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment