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

Leave a Reply