memize
memize copied to clipboard
Scope Issue
Won't this fail if someone has memoized a method on an object and called it on the object?
node = {
args: args,
// Generate the result from original function
val: fn.apply(null, args),
};
I'm not sure I follow the concern. Could you provide a sample code snippet of a memize-memoized function result which demonstrates the issue?
sure! ... not that you would ever write and memoize the below, but it illustrates the point
const o = {
length: 10,
width: 10,
height: 10,
volume() { return this.length * this.width * this.height; }
}
o.volume = memize(0.volume);
v.volume(); // will throw because this is null
Ah, yeah, I see the issue now. On first glance, I'd wonder if it'd be fine enough to swap out null with this, but I'd need to write some tests to confirm, and check for any potential performance impact.
The world deserves the best. I am happy to fork and test if you wish.
On Sun, Jun 18, 2023 at 6:45 AM Andrew Duthie @.***> wrote:
Ah, yeah, I see the issue now. On first glance, I'd wonder if it'd be fine enough to swap out null with this, but I'd need to write some tests to confirm, and check for any potential performance impact.
— Reply to this email directly, view it on GitHub https://github.com/aduth/memize/issues/13#issuecomment-1596152639, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABF2US4GK6YRG6GBO3ZFM5LXL4A6XANCNFSM6AAAAAAZJL3FFA . You are receiving this because you authored the thread.Message ID: @.***>