JavaScript The Good Parts

Friday, 23. January 2009

“JavaScript The Good Parts” by Douglas Crockford is one of the most subjective books on JavaScript because it dares to divide JavaScript language specifications into good parts and bad parts.

Most of good parts are well-known, but not widely used. I can see they are fully and correctly used in JavaScript frameworks or toolkits but they are rarely or inappropriately used by page designers.

For me, sections on bad parts are much useful. I tell “===” from “==” but I have never used “===” just because I, as a Java programmer, am not familiar to it. The book helps use bad parts less rather than use good parts more.

Pro JavaScript Techniques

Tuesday, 29. January 2008

The “Pro JavaScript Techniques” authored by John Resig, the creator of jQuery, is a excellent book. I neither bought nor read the book. Instead I just read sample code snippets from http://jspro.org/code/ and tested them. Guessing from the code snippets, Ch.2 and Ch.3 describe backgrounds of JavaScript. I think these chapters are the core of this book and they really help us understand the concept of “prototype-based” and write object-oriented JavaScript code gracefully. Remaining chapters are for advanced techniques and tips: Ajax, DOM, cross-browser supporting, new features of JavaScript 1.6/1.7 and so on. Even though these chapters are not so much impressive to me, they also seem to be worthwhile to read.

JavaScript function considered a first-class object

Monday, 26. November 2007

JavaScript is a prototype based language, and it has many characteristics of functional languages. For example, JavaScript regards a function as a first-class object. Among many type checking functions YUI provides, YAHOO.lang.isObject() reflects the characterstic.


<script src="http://yui.yahooapis.com/2.3.1/build/yahoo/yahoo-min.js" type="text/javascript"></script>
foo= function() {} // function is storable in variables
YAHOO.lang.isObject(foo) // returns true

JavaScript coding style

Sunday, 11. November 2007

When I was a beginner of JavaScript, I don’t have to use OOP.
As system grows, I put more value on modular design and code reuse.

Some technique enabling OOP were helpful. I just enjoyed the encapsulation technique.


ClassA = function(){
this.funcA = function(){
}
this.funcB = function(){
}
}

Later, I knew that using “prototype” is more efficient in memory usage. Refer to this.


ClassA = function(){
}
ClassA.prototype.funcA = function(){
}
ClassA.prototype.funcB = function(){
}

Now, I found more readable and concise style from YUI.


ClassA = function(){
}
ClassA.prototype = {
funcA: function(){
},
funcB: function(){
}
}