Skip to content

Commit b8b45d1

Browse files
committed
Merge pull request documentcloud#190 from codelahoma/docs
improve builders documentation
2 parents 610d473 + 8f2cb9b commit b8b45d1

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

docs/underscore.object.builders.js.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,26 @@ _.frequencies(citations);
2424

2525
**Signature:** `_.merge(obj1:Object[, obj:Object...])`
2626

27-
Merges two or more objects starting with the left-most and applying the keys
28-
rightward.
27+
Returns a new object resulting from merging the passed objects. Objects
28+
are processed in order, so each will override properties of the same
29+
name occurring in earlier arguments.
30+
31+
Returns `null` if called without arguments.
2932

3033
```javascript
31-
_.merge({ a: "alpha" }, { b: "beta" });
32-
// => { a: "alpha", b: "beta" }
34+
var a = {a: "alpha"};
35+
var b = {b: "beta"};
36+
37+
var threeGreekLetters = _.merge(a, b, {g: "gamma"});
38+
39+
a;
40+
// => {a: "alpha"}
41+
42+
b;
43+
// => {b: "beta"}
44+
45+
threeGreekLetters;
46+
// => { a: "alpha", b: "beta", g: "gamma" }
3347
```
3448

3549
--------------------------------------------------------------------------------
@@ -56,11 +70,26 @@ Sets the value of a property at any depth in `obj` based on the path described
5670
by the `ks` array. If any of the properties in the `ks` path don't exist, they
5771
will be created with `defaultValue`.
5872

59-
See `_.updatePath` about `obj` not being mutated in the process by cloning it.
73+
Note that the original object will *not* be mutated. Instead, `obj` will
74+
be cloned deeply.
75+
76+
6077

6178
```javascript
62-
_.setPath({}, "Plotinus", ["Platonism", "Neoplatonism"], {});
79+
80+
var obj = {};
81+
82+
var plotinusObj = _.setPath(obj, "Plotinus", ["Platonism", "Neoplatonism"], {});
83+
84+
obj;
85+
// => {}
86+
87+
plotinusObj;
6388
// => { Platonism: { Neoplatonism: "Plotinus" } }
89+
90+
obj === plotinusObj;
91+
// => false;
92+
6493
```
6594

6695
--------------------------------------------------------------------------------
@@ -83,6 +112,8 @@ schools === _.snapshot(schools);
83112

84113
--------------------------------------------------------------------------------
85114

115+
#### updatePath
116+
86117
**Signature:** `_.updatePath(obj:Object, fun:Function, ks:Array, defaultValue:Any)`
87118

88119
Updates the value at any depth in a nested object based on the path described by
@@ -115,3 +146,5 @@ obj;
115146
obj === imperialObj;
116147
// => false
117148
```
149+
150+
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)