ES6中的私有道具不适用于WeakMap

时间:2015-09-06 11:45:17

标签: javascript node.js ecmascript-6 babeljs

我创建了以下类:

import Confidence from 'confidence';

import manifest from './manifest';
import criteria from './criteria';

const privateProps = new WeakMap();

class Configuration {

    constructor() {
        privateProps(this, { store: new Confidence.Store(manifest) });
    }

    getKey(key) {
        return privateProps.get(this).store.key(key, criteria);
    }

    getMeta(key) {
        return privateProps.get(this).store.meta(key, criteria);
    }
}

let configuration = new Configuration();
export default configuration;

为了使store道具私密,因为在ES6中到目前为止没有机会拥有私人道具。不幸的是与babel交流我得到了这个错误:

privateProps(this, { store: new _confidence2['default'].Store(_manifes

TypeError: object is not a function

知道哪里出错了?

1 个答案:

答案 0 :(得分:2)

如错误所示,privatePropsWeakMap实例)不是函数。

你可能意味着:

privateProps.set(this, { store: new Confidence.Store(manifest) });