home wiki.fukuchiharuki.me
Menu

function FirstClassCollection() {
  this.__content;
}
FirstClassCollection.prototype.size = function () {
  return this.__content.length;
};
FirstClassCollection.prototype.map = function (...args) {
  const newCollection = Object.create(Object.getPrototypeOf(this));
  newCollection.__content = this.__content.map(...args);
  return newCollection;
};

function asFirstClassCollection(target) {
  Object.setPrototypeOf(target, FirstClassCollection.prototype);
  return target;
}
function RaisableCollection() {
  this.__content;
}
Object.setPrototypeOf(RaisableCollection.prototype, FirstClassCollection.prototype);
RaisableCollection.prototype.raise = function() {
  return this.map(value => value * value)
};

function asRaisableCollection(target) {
  Object.setPrototypeOf(target, RaisableCollection.prototype);
  return target;
}