Welches sollte der bessere Ansatz sein, um JavaScript-Code zu schreiben, und warum?Welcher von diesen sollte der bessere Ansatz sein, JavaScript-Code zu schreiben?
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 myObj = {
init : function(x, y)
{
this.width = x;
this.height = y;
},
show : function()
{
alert("width = "+ this.width+" height = "+ this.height);
}
}
Markdown behandelt nicht Listen gefolgt von Code korrekt, nie hat ... leicht bearbeitet, um die richtige Formatierung zu bekommen :) –