Tim Van Wassenhove home

This week i have been reading JavaScript: The Good Parts. Although the book is pretty thin, approximitaly. 150 pages, the information that is inside the book is really powerful. The book provides deep insight for people that are considering to implement functionality in JavaScript. I would say that this is a must read.

Here is an example of something that i learned from the book (A workaround for an error in the ECMAScript Language Specification which causes this to be set incorrectly for inner functions)

function Broken(name) {
	this.name = name;
	function GetName() { return this.name; }
	this.Display = function() { alert(GetName()); }
}

new Broken("broken").Display(); // displays 'undefined'

and

function Fixed(name) {
	var that = this;
	this.name = name;
	function GetName() { return that.name; }
	this.Display = function() { alert(GetName()); }
}

new Fixed("fixed").Display(); // displays 'fixed'