在构造函数,javascript上自动添加继承作为属性

时间:2017-01-31 20:35:59

标签: javascript inheritance web-worker

我将(重)文件解析器移动到webworker。 Web工作者只能返回序列化的json。因此,我无法返回给我的对象继承特定类的函数:

getCollection: function getCollection(cls) {
  if (!cls) {
    return this.myObjects;
  }
  let collection = cls.toUpperCase();

  let arr = [];

  for (let i = 0; i < this.nrOfObjects; i++) {
    if(classes[collection]){
      if (this.myObjects[i] instanceof classes[collection]) {
        arr.push(this.myObjects[i]);
      }
    }
  }

  return arr;
}

因此,例如getCollection('product')将返回继承自类product的所有实例

当我将解析器移动到webworker时,我无法返回此功能。无论如何我可以在我的类中将继承添加到我的构造函数中吗?

export class Column extends BuildingElment {
  constructor(GlobalId, OwnerHistory, Name, Description) {
    super(GlobalId, OwnerHistory, Name);
    this.description = Description
    this.nameOfClass = 'Column';
    this.inheritance = ['Root', 'Product', 'BuildingElement'] // Can this be somehow automatically generated??
  }
}

或者,如果有任何其他方式,我可以与webworkers合作,仍然可以获得继承。

0 个答案:

没有答案