【发布时间】:2017-07-03 09:46:08
【问题描述】:
我正在尝试将函数传递给Map,就像使用对象文字表示法一样。 Immutable 是否有任何本机方法可以调用该函数,就好像您在可枚举对象上使用 getter 方法一样?
var person = {
firstName: 'John',
lastName: 'Smith',
format: function() {
return this.lastName + ', ' + this.firstName;
}
};
person.format(); // 'Smith, John'
var personMap = new Immutable.Map(person);
personMap.get('format'); // function() {return ... // doesn't work
【问题讨论】:
-
你能量化“更清洁”吗?我认为
format也不会在这里拥有正确的this。 -
为了清楚起见,我进行了编辑。
-
我只想说 immutable.js 不能这样工作。代码中的
this肯定指向其他地方。 -
感谢您的澄清。
标签: javascript immutable.js enumerable