javascript - How to write this function? What are the advantages?
大家讲道理
大家讲道理 2017-05-19 10:10:57
0
6
445
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?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(6)
Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template