【发布时间】:2012-11-14 00:03:56
【问题描述】:
我一直在寻找有关如何在 ECMAScript 6 中将符号指定为公共或私有的讨论。
据我了解,私有符号将使用类似于以下的模式创建:
var itemManager = (function() {
var items = new Symbol(/* possible string description? */);
return {
[items]: [ ],
getItems: function() {
return this[items].slice();
},
addItem: function(item) {
this[items].push(item);
}
};
})();
但是我如何将items 符号指定为公开?在 ES6 中是否可以使用公共符号,或者它们只会是私有的(例如,不会出现在 Object.getOwnPropertyNames 中)?此外,默认情况下公共符号是否可枚举(显示在 Object.keys 中)?
谁能给我链接相关信息?
【问题讨论】:
-
只需将其定义为数据属性即可。
标签: javascript ecmascript-harmony ecmascript-6