0
我想将具有属性(键)的对象映射到装饰器(值)。如果可能,我想使用弱映射。我有一个正在使用字符串的解决方案,除了弱地图不接受字符串作为关键字。这是可能的一个地图或WeakMap?ES6将对象映射到装饰器
'use strict';
class Accordion {
constructor() {}
}
let Decorators = new Map();
Decorators.set({nodeName: 'tag-name-here', component: 'accordion'}, (client) => { return new Accordion(client) });
class Client {
constructor() {
let key = {nodeName: 'tag-name-here', component: 'accordion'}
let decorator;
if (Decorators.has(key)) {
decorator = Decorators.get(key)(this);
}
console.log(decorator); //undefined, unless I use a string as a key.
}
}
new Client();