Skip to content

Conversation

@GustavoEdinger
Copy link

This fix addresses a reference issue with getData and setData during reset operations.
Previously, after a reset, getData would continue returning stale data because it maintained a reference to the old data object.

This occurred because Object.assign does not update the execution context of copied functions. The function reference remained bound to the original data even after resetting.

Here's a quick example of the problem.

function func (newData) {

   const data = newData;
  
  function nestedFunc() {
    console.log(data);
  }

  return {nestedFunc};
}

const a = func("original data");
const b = func("new data");

a.nestedFunc(); // "original data"

Object.assign(a.nestedFunc, b.nestedFunc);

a.nestedFunc(); // "original data"

https://jsbin.com/huwataloru/edit?js,console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant