If one has an existing object obj
:
const obj = {
i: 0,
foo(){
console.log(this.i)
this.i +=1
}
}
obj.foo() // => 0
Is it possible to merge a function into it:
// the following function code should be added to `obj`
function obj(){
this.foo()
}
// after the merge the following should both work:
obj.foo() // => 1
obj() // => 2