-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Comments
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! |
Well, store.get(...) || default would use default if the get return is false-y. To be equivalent, it would need to be: |
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! |
Well, my other commit serializes to JSON if available. I need that one, this one is just nice. :-) |
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?
The text was updated successfully, but these errors were encountered: