我在尝试从 ecmascript 6 中可用的新 Set
继承时遇到问题。该类定义如下:
function SelectionManager () {
Set.call(this);
}
SelectionManager.prototype = Object.create(Set.prototype);
SelectionManager.prototype.add = function (unit) {
unit.setIsSelected(true);
Set.prototype.add.call(this, unit);
};
/* Some functions left out */
尝试调用 add
时出现以下错误:TypeError: Set operation called on non-Set object
代码可在 http://jsfiddle.net/6nq1gqx7/ 获得
draft for ES6明确指出应该可以对 Set 进行子类化,正确的做法是什么?
最佳答案
关于javascript - 在javascript中子类化ES6集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26255775/