Aku punya kelas super yang merupakan induk ( Entity) untuk banyak subclass ( Customer, Product, ProductCategory...)
Saya mencari untuk mengkloning secara dinamis suatu objek yang berisi sub objek yang berbeda dalam naskah.
Sebagai contoh: a Customeryang berbeda Productyang memiliki aProductCategory
var cust:Customer = new Customer ();
cust.name = "someName";
cust.products.push(new Product(someId1));
cust.products.push(new Product(someId2));
Untuk mengkloning seluruh pohon objek saya membuat fungsi di Entity
public clone():any {
var cloneObj = new this.constructor();
for (var attribut in this) {
if(typeof this[attribut] === "object"){
cloneObj[attribut] = this.clone();
} else {
cloneObj[attribut] = this[attribut];
}
}
return cloneObj;
}
The newnaik error berikut ketika transpiled ke javascript:error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
Meskipun skrip berfungsi, saya ingin menyingkirkan kesalahan yang ditransformasikan