0
我想創建一個簡單的JavaScript/HTML5畫布引擎,支持我的動畫數組length屬性JavaScript對象原型中沒有發現
引擎(這主要是出於學習目的):
/* BOF GLOBAL REFERENCES*/
var BM = BM || {};
/* EOF GLOBAL REFERENCES */
/* BOF GLOBAL VARIABLES */
/* EOF GLOBAL VARIABLES */
/* BOF FUNCTIONS */
BM.World = function(container,width,height,name){
this.container = $("#"+container);
this.width = width;
this.height = height;
this.name = name || "DefaultWorld";
this.layers = new Array();
}
BM.World.prototype.Layer = function(options){
var options = options || {};
options.bgcolor = options.bgcolor || "transparent";
this.container.html("<canvas id='"+this.name+"_layer_"+this.layers.length+"' style='position:absolute;top:0;left:0;width:"+this.width+";height:"+this.height+";background:"+options.bgcolor+";'>"
+"</canvas>");
}
/* EOF FUNCTIONS */
而簡單的主叫代碼:
$(function(){
var World = new BM.World("background_container",400,600);
var layer1 = new World.Layer({bgcolor:"#ff0000"});
});
有人能告訴我什麼,我在Layer
定義做錯了什麼?我得到的錯誤是:Uncaught TypeError: Cannot read property 'length' of undefined