Is it possible to modify all references to an anonymous function so that invocations from other objects reflects the changes?
Below is an example of a situation where obj1.name and obj2.name both points to the same function, but since the function is passed by value when creating obj2.name = obj1.name, changes in obj1.name doesn't affect obj2.name.
In this example, I would like to modify that function so that it returns 'edited' for all objects.
//This two declarations are part of the original code that I cannot modify.
let obj1 = {
name: function() { return 'original'; }
}
let obj2 = {
name: obj1.name
}
// obj1.name() >> 'original'
// obj2.name() >> 'original'
// At this point, I want to modify the returned value.
obj1.name = function() { return 'edited'; }
// obj1.name() >> 'edited'
// obj2.name() >> 'original'