rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

Functions are not made to have immutable properties. #85

Closed lewisje closed 8 years ago

lewisje commented 8 years ago

I just browsed through the code and saw that it considers val to be mutable if and only if null !== val and typeof val === 'object'; however, functions can be mutated, much like an ordinary object (their internal [[Call]] properties are immutable, but ordinary properties can still be added, changed, or removed), and I think that typeof val === 'function' should also work, or in sum:

(null !== val && typeof val === 'object') || typeof val === 'function'

I am also aware of the non-standard typeof value 'unknown' but I believe that only exists in oldIE, where Object.defineProperty only works on DOM nodes if it exists at all, and those "unknown" type objects are already immutable IIRC.

rtfeldman commented 8 years ago

This was an early design decision (https://github.com/rtfeldman/seamless-immutable/issues/5) - is there a use case where the current behavior is causing a problem?

lewisje commented 8 years ago

I didn't notice that closed issue, and I don't actually use the library; I just read the source and remembered how some tutorials on memoization implement it with properties on the functions themselves.