2.12 枚举类(Enum)

枚举类是为了让开发者在属性参数设置时更容易理解其代表的含义,所定义的类,拿BufferAnalysis来举例:

var bufferAnalysis = new CooSDK.BufferAnalysis({
    drawableType: CooSDK.EnumBufferType.POINT
});

这里的drawableType属性表示的是缓冲区类型,该属性类型为EnumBufferType,其内部有三种值:POINTLINEPOLYGON

POINT代表缓冲区,LINE代表线缓冲区,POLYGON代表缓冲区。在原生API中,它们对应的是数值类型的0、1和2,如果不看代码相关注释,是不知道0、1、2具体指代含义的,因此在JS API中,对这些参数做了枚举定义:

var EnumBufferType = {
    /**
        * 点缓冲区。
        * @type {Number}
        * @constant
        */
    POINT: 0,

    /**
        * 线缓冲区。
        * @type {Number}
        * @constant
        */
    LINE: 1,

    /**
        * 面缓冲区。
        * @type {Number}
        * @constant
        */
    POLYGON: 2
};

通过枚举类的定义,我们就可以通过其字面意思及API文档注释,很快了解参数该如何传值,提高对代码的理解,提高开发效率。

results matching ""

    No results matching ""