Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memoization using multiple argument as JSON-key #56

Closed
Bartvds opened this issue Mar 29, 2012 · 1 comment
Closed

memoization using multiple argument as JSON-key #56

Bartvds opened this issue Mar 29, 2012 · 1 comment

Comments

@Bartvds
Copy link

Bartvds commented Mar 29, 2012

I was looking at the memoization patterns and specifically 'preferred method 2' (multiple arguments using JSON stringify) and noticed a possible issue:

var cachekey = JSON.stringify(Array.prototype.slice.call(arguments)),

Maybe it should mention that this will only work correctly for primitive (and Array) arguments, since the order in which properties of Objects are enumerated is undetermined and can even change between enumerations. (a JSON encoder that sorts the keys won't have this issue).

Take for example this object:

{a:1, b:2}

Could on execution result in theseJSONs and so miss the cache.
"{'a':1, 'b':2}"
"{'b':2, 'a':1}"

@chuanxshi
Copy link
Owner

thanx for the comment, note added :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants