【发布时间】:2015-08-11 19:59:55
【问题描述】:
我在 node.js 应用程序中使用 Javascript ES6 功能:
class pairKey {
constructor(x_pos, y_pos) {
this._X = x_pos;
this._Y = y_pos;
}
get x() {
return this._X;
}
set x(x_pos) {
this._X = x_pos;
}
get y() {
return this._Y;
}
set y(y_pos) {
this._Y = y_pos;
}
var allElem = new Map();
allElem.set(new pairKey(1,2), 'a');
allElem.set(new pairKey(2,3), 'b');
console.log(allElem.has(new pairKey(1,2))); //Should return true instead return false
在这段代码中,我想使用一对 Int 作为我的地图键 (allElem)。
问题是我不知道 Map 如何比较 javascript 中的对象。
有人可以帮助我吗?
【问题讨论】:
标签: javascript dictionary ecmascript-6