memize icon indicating copy to clipboard operation
memize copied to clipboard

Scope Issue

Open anywhichway opened this issue 2 years ago • 4 comments

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),
		};

anywhichway avatar Jun 16 '23 14:06 anywhichway

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?

aduth avatar Jun 17 '23 02:06 aduth

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

anywhichway avatar Jun 17 '23 12:06 anywhichway

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.

aduth avatar Jun 18 '23 13:06 aduth

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: @.***>

anywhichway avatar Jun 18 '23 16:06 anywhichway