Can you help me troubleshoot an issue in this simplified class code snippet? I'm attempting to dynamically assign values to this by looping over key values in the constructor, but it's not working as expected. Could this be a syntax problem or is it not feasible to do in this context?
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
}
}