what should be the good approach to write javascript code?

Posted by Bhupi on Stack Overflow See other posts from Stack Overflow or by Bhupi
Published on 2010-12-29T11:50:34Z Indexed on 2010/12/29 11:54 UTC
Read the original article Hit count: 117

Filed under:

Hi,

which should be the good approach to write javascript code and why?

1)

var myClass = function(){}

myClass.prototype.init = function(x, y){
        this.width = x;
        this.height = y;
    }

myClass.prototype.show = function(){
        alert("width = "+ this.width+" height = "+ this.height);
}

2)

var myNewClass = {
        init : function(x, y)
        {
            this.width = x;
            this.height = y;
        },
        show : function()
        {
            alert("width = "+ this.width+" height = "+ this.height);    
        }           
    }

© Stack Overflow or respective owner

Related posts about JavaScript