Here is a simplified class. I try to loop over key values in constructor, to dynamically assign values to this. But it doesn't work. Is it a syntax problem ? Or is it not possible ?
class DirectoryModel {
public link_title: string
public link_desc: string
constructor(fields: any) {
console.log(fields) // ok
_.forOwn(fields, function (value, key) {
console.log(key) // ok
console.log(value) // ok
this[key] = value // "Cannot set property 'link_title' of undefined"
})
// this.link_title = fields.link_title
// this.link_desc = fields.link_desc
}
}
thiswill probably bewindow.