-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Return object from the .set()
method
#42
Return object from the .set()
method
#42
Conversation
Do you have an example of that? I'm trying to think of when it would be useful. |
readme.md
Outdated
@@ -59,7 +63,7 @@ console.log(obj); | |||
|
|||
### get(obj, path, [defaultValue]) | |||
|
|||
### set(obj, path, value) | |||
### obj = set(obj, path, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to write it in text. Something like:
Returns the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! See new commit.
@sindresorhus As an example, I have a function that takes a value, does something to it, and returns it at a path in a new object. (The path is provided at run-time, so regular JS object notation is not an option.) When
With this PR I could simply write:
It's not a big issue – just for convenience. :) |
Makes sense. Can you use something like that in the readme example too? |
Sure. I had an example of the return value, but it wasn't clear enough. Changed the input to an empty object, so it is clearer what the point of it is. Sorry I didn't return a unicorn. |
.set()
method
Just a small change to return the object from the
set
method. I find it convenient in some cases, and it does not add any significant overhead.Feel free to merge if this makes sense to you. Tests and readme are updated accordingly.