prismock
prismock copied to clipboard
fix: reset reference to get and set data
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