There seems to be a strange occurrence happening with the data below:
// data
visitorsTemplate: [{
text: '',
type: 'buttons',
children: [{
name: 'email',
method: (e) => { this.sendEmail(e) }
}]
}]
When it is cloned using the following function:
// watch
console.log(this.visitorsTemplate)
const visitorItem = clone(this.visitorsTemplate)
console.log(visitorItem)
Utilizing this cloning function:
// utils
export const clone = (...args) => {
return JSON.parse(JSON.stringify.apply(null, args))
}
The method attribute mysteriously disappears after the cloning process. The console logs show the changes made:
[{
text: "",
type: "buttons",
children": [{
name: "email",
method: f method(e)
}, {
name: "delete",
method: f method(e)
}]
}]
[{
text: "",
type: "buttons",
children": [{
name: "email"
}, {
name: "delete"
}]
}]
Update: It has been discovered that JSON.stringify is causing the removal of the methods
, but in order to create a new array while retaining these methods, what steps should be taken?