Closed martincastell closed 9 years ago
On line 5 - if you add a console.log:
console.log(_.setPath(myObj, 'after', ['level1', 'level2', 'level3'], {}));
You'll see that setPath returns a new object with the updated property.
I see that, but from the docs it sounds to me like .setPath modifies the object and .updatePath creates a copy (like _.setPath is doing right now).
See _.updatePath about obj not being mutated in the process by cloning it.
@martincastell:
Both _.setPath
and _.updatePath
return new objects without mutating the one passed to them (they're both in the object.builders sub-library, after all).
Looking at the source, _.setPath
actually calls _.updatePath
to get its work done.
The documentation you quoted is awkwardly worded. I believe the intent was to say that the lack of object mutation mentioned in the _.updatePath
documentation applies to _.setPath
as well, which it does.
I'll try to clarify the doc and submit a PR.
According to the docs, _.setPath:
Using .updatePath would create a copy, it sounds like .setPath should modify the original object, but it's not happening right now. JSFiddle: http://jsfiddle.net/ds2qa8bc/1/