使用枚举来定义另一个枚举

时间:2014-01-27 11:17:53

标签: javascript enums rhino

允许在JavaScript中使用枚举来定义另一个枚举吗?

var VESSEL_DOCUMENT_SUB_TYPE = {
//  PLAN_TYPE           :   {
//      
//  },
    /** @enum {Number} */
    CERTIFICATE_TYPE    :   {
        BUNKER_OIL_POLLUTION_DAMAGE :   CERTIFICATE_TYPE.BUNKER_OIL_POLLUTION_DAMAGE,
        P_I_COE                     :   CERTIFICATE_TYPE.P_I_COE,
        H_M_SINGLE_COVER_NOTE       :   CERTIFICATE_TYPE.H_M_SINGLE_COVER_NOTE
    }/*,
    OTHER               :   {

    }*/
};

var CERTIFICATE_TYPE = {
    /** Bunker Oil Pollution Damage */
    BUNKER_OIL_POLLUTION_DAMAGE :   0,
    /** P&I (COE) */
    P_I_COE                     :   1,
    /** H&M Single Cover Note */
    H_M_SINGLE_COVER_NOTE       :   2
};

1 个答案:

答案 0 :(得分:2)

是的,这是允许的。唯一的问题是,我收到运行时错误,因为CERTIFICATE_TYPE应该在VESSEL_DOCUMENT_SUB_TYPE之前定义

var CERTIFICATE_TYPE = {
    /** Bunker Oil Pollution Damage */
    BUNKER_OIL_POLLUTION_DAMAGE :   0,
    /** P&I (COE) */
    P_I_COE                     :   1,
    /** H&M Single Cover Note */
    H_M_SINGLE_COVER_NOTE       :   2
};

var VESSEL_DOCUMENT_SUB_TYPE = {
//  PLAN_TYPE           :   {
//      
//  },
    /** @enum {Number} */
    CERTIFICATE_TYPE    :   {
        BUNKER_OIL_POLLUTION_DAMAGE :   CERTIFICATE_TYPE.BUNKER_OIL_POLLUTION_DAMAGE,
        P_I_COE                     :   CERTIFICATE_TYPE.P_I_COE,
        H_M_SINGLE_COVER_NOTE       :   CERTIFICATE_TYPE.H_M_SINGLE_COVER_NOTE
    }/*,
    OTHER               :   {

    }*/
};