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?
Object-oriented programming, if there are any advantages to this way of writing, avoid polluting global variables
This is a method of an object
Object literal function
Object literal writing method, this code creates a CanvasDraw object, not a constructor.
Thanks for the invitation! This is object-oriented programming. It's not a constructor, the constructor is a method, you are just an object.
The one with new is the constructor. This is how you write the object literal