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(){
}
}

Misuse of “Array” as an associative array

Tuesday, 30. October 2007

The difference between array and associative array is so clear that developers never misuse them.
In fact, if they misuse them in a specific programming language, compiler or interpreter will detect the error.
But JavaScript is exceptional. Unfortunately, it allows careless developers to use “Array” as an associative array.
Thanks to the article that awakes me. It doesn’t take a long time to find silly mistakes in my code.

Unobtrusive JavaScript

Monday, 29. October 2007

About 1 year ago, I had to implement CRUD operation on existing HTML table. I found that manupulating DOM element enables functions such as adding or deleting rows, sorting table. But it was not simple and code got bigger and bigger as each function is implemented one by one. At that times, sortable table example provided valuable insight. It was implemented in unobtrusive way.

Nowdays, if I am asked to use the grid-like control on the WEB, I will not hesitate to select YUI. Check out YUI if you want to know the beauty of unobtrusive JavaScript.