var CanvasDraw = {
canvas:null,//canvas元素
context:null,//canvas环境
fps:30,//帧频
type:null, //类型 letter或 img 对象
drawObj:null,
gap:null,
dotsData:[],
dots:[],
Init:function(canvas,width,height,type,drawObj,gap,fps,fn){
CanvasDraw.canvas = canvas;
CanvasDraw.context = canvas.getContext("2d");
CanvasDraw.canvas.width=width;
CanvasDraw.canvas.height=height;
CanvasDraw.fps = fps || 30;
CanvasDraw.type = type || "letter";
CanvasDraw.gap=gap||10;
CanvasDraw.drawObj=drawObj;
CanvasDraw.dotsData=[];
CanvasDraw.dots=[];
CanvasDraw.ShapeBuilder.Init();
},
Render:function(canvas,width,height,type,drawObj,fps,fn){
this.Init(canvas,width,height,type,drawObj,fps,fn);
},
StopRender:function(fn){
}
}
Also, is this a constructor?
天蓬老师2017-05-19 10:12:57
Object-oriented programming, if there are any advantages to this way of writing, avoid polluting global variables
漂亮男人2017-05-19 10:12:57
Object literal writing method, this code creates a CanvasDraw object, not a constructor.
世界只因有你2017-05-19 10:12:57
Thanks for the invitation! This is object-oriented programming. It's not a constructor, the constructor is a method, you are just an object.
阿神2017-05-19 10:12:57
The one with new is the constructor. This is how you write the object literal