alexreardon / memoize-one

A memoization library which only remembers the latest invocation
MIT License
2.95k stars 79 forks source link

memoized function has no length #38

Open ChristopherChudzicki opened 6 years ago

ChristopherChudzicki commented 6 years ago

Memoizing a function sets its length property to zero:

import memoizeOne from 'memoize-one'
f = (a, b, c) => a*b*c
memoF = memoizeOne(f)
console.log(f.length) // 3
console.log(memoF.length) // 0

This is not really a big deal: length is a configurable property, so if you care about f.length you can just set it manually afterwards using Object.definiteProperty.

Should memoizeOne automatically configure the memoized functions length property?

alexreardon commented 6 years ago

At one point we tried adding this, but it broke ie11 #18

We could wrap the assignment in a try / catch...

I am not sure what the best path forward is. /cc @theKashey

theKashey commented 6 years ago

We shall just redo #18

alexreardon commented 5 years ago

Maybe if we wrap it in a try catch? My issue is that people might expect the function to have a length in ie11 - but it wont

theKashey commented 5 years ago

There is 2 ways to define length