我正在尝试创建一个简单的 javascript/html5 画布引擎来支持我的动画(这主要用于学习目的。)
引擎:
/* 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