看到pomelo中對于常量的處理方法,覺得這種方法真的是值得推薦的.?
常量在一個較大型的工程里,他的作用或許不大,但由他帶來的麻煩有時候挺大的.
推薦大家看一下pomelo的源碼中的 pomelo/lib/util/constants.js 對于常量的定義.自己和喜歡這種格式的數據,使用起來特別的方便.
{key1 : {}, key2 : {}, key3 : {}}
使用的時候:
var Constants = require('./util/constants');
var routes = this.get(Constants.KEYWORDS.ROUTE);
獲取到ROUTE 定義的常量