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

.get returning default #6

Closed
jdunck opened this issue Jul 1, 2010 · 4 comments
Closed

.get returning default #6

jdunck opened this issue Jul 1, 2010 · 4 comments

Comments

@jdunck
Copy link

jdunck commented Jul 1, 2010

I think it would be useful to have .get take an optional param which is returned iff the requested key is missing (or has an undefined value).

Agree?

@marcuswestin
Copy link
Owner

Hey jdunck,

Thanks for the request!

Would (store.get(key, defaultValue)) act differently from (store.get(key) || defaultValue)? If not, I think it's to the advantage of a user of store.js to add a parameter to the .get signature.

Cheers!

@jdunck
Copy link
Author

jdunck commented Jul 1, 2010

Well, store.get(...) || default would use default if the get return is false-y. To be equivalent, it would need to be:
store.get(...) == undefined || default.
I'm just trying make use a bit more concise, but it's a small matter.

@marcuswestin
Copy link
Owner

Since local storage coerces values into string store.set('foo', false); store.get('foo') == 'false'.

Thanks for the suggestion, but I think keeping a clean and straight-forward small implementation that's easily modified will serve everyone well.

Closing the issue for now - feel free to reopen if you believe there are strong reasons to implement the feature.

Thanks!

@jdunck
Copy link
Author

jdunck commented Jul 1, 2010

Well, my other commit serializes to JSON if available. I need that one, this one is just nice. :-)

This issue was closed.
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