Skip to content

Commit 416b502

Browse files
committed
Rename extendOwn to assign
“assign” is an ES6 standard, and naming should match it. Any dev who remotely follows ES will immediately recognize and understand what it does. Aliases `_.assign` to `_.extendOwn`, for 1.8.0 compatibility.
1 parent 1669e07 commit 416b502

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,8 +1436,9 @@ <h2 id="objects">Object Functions</h2>
14361436
=&gt; {name: 'moe', age: 50}
14371437
</pre>
14381438

1439-
<p id="extendOwn">
1440-
<b class="header">extendOwn</b><code>_.extendOwn(destination, *sources)</code>
1439+
<p id="assign">
1440+
<b class="header">assign</b><code>_.assign(destination, *sources)</code>
1441+
<span class="alias">Alias: <b>extendOwn</b></span>
14411442
<br />
14421443
Like <b>extend</b>, but only copies <i>own</i> properties over to the
14431444
destination object.

test/objects.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,33 @@
136136
strictEqual(_.extend(undefined, {a: 1}), undefined, 'extending undefined results in undefined');
137137
});
138138

139-
test('extendOwn', function() {
139+
test('assign', function() {
140140
var result;
141-
equal(_.extendOwn({}, {a: 'b'}).a, 'b', 'can assign an object with the attributes of another');
142-
equal(_.extendOwn({a: 'x'}, {a: 'b'}).a, 'b', 'properties in source override destination');
143-
equal(_.extendOwn({x: 'x'}, {a: 'b'}).x, 'x', "properties not in source don't get overriden");
144-
result = _.extendOwn({x: 'x'}, {a: 'a'}, {b: 'b'});
141+
equal(_.assign({}, {a: 'b'}).a, 'b', 'can assign an object with the attributes of another');
142+
equal(_.assign({a: 'x'}, {a: 'b'}).a, 'b', 'properties in source override destination');
143+
equal(_.assign({x: 'x'}, {a: 'b'}).x, 'x', "properties not in source don't get overriden");
144+
result = _.assign({x: 'x'}, {a: 'a'}, {b: 'b'});
145145
deepEqual(result, {x: 'x', a: 'a', b: 'b'}, 'can assign from multiple source objects');
146-
result = _.extendOwn({x: 'x'}, {a: 'a', x: 2}, {a: 'b'});
146+
result = _.assign({x: 'x'}, {a: 'a', x: 2}, {a: 'b'});
147147
deepEqual(result, {x: 2, a: 'b'}, 'assigning from multiple source objects last property trumps');
148-
deepEqual(_.extendOwn({}, {a: void 0, b: null}), {a: void 0, b: null}, 'assign copies undefined values');
148+
deepEqual(_.assign({}, {a: void 0, b: null}), {a: void 0, b: null}, 'assign copies undefined values');
149149

150150
var F = function() {};
151151
F.prototype = {a: 'b'};
152152
var subObj = new F();
153153
subObj.c = 'd';
154-
deepEqual(_.extendOwn({}, subObj), {c: 'd'}, 'assign copies own properties from source');
154+
deepEqual(_.assign({}, subObj), {c: 'd'}, 'assign copies own properties from source');
155155

156156
result = {};
157-
deepEqual(_.extendOwn(result, null, undefined, {a: 1}), {a: 1}, 'should not error on `null` or `undefined` sources');
157+
deepEqual(_.assign(result, null, undefined, {a: 1}), {a: 1}, 'should not error on `null` or `undefined` sources');
158158

159159
_.each(['a', 5, null, false], function(val) {
160-
strictEqual(_.extendOwn(val, {a: 1}), val, 'assigning non-objects results in returning the non-object value');
160+
strictEqual(_.assign(val, {a: 1}), val, 'assigning non-objects results in returning the non-object value');
161161
});
162162

163-
strictEqual(_.extendOwn(undefined, {a: 1}), undefined, 'assigning undefined results in undefined');
163+
strictEqual(_.assign(undefined, {a: 1}), undefined, 'assigning undefined results in undefined');
164164

165-
result = _.extendOwn({a: 1, 0: 2, 1: '5', length: 6}, {0: 1, 1: 2, length: 2});
165+
result = _.assign({a: 1, 0: 2, 1: '5', length: 6}, {0: 1, 1: 2, length: 2});
166166
deepEqual(result, {a: 1, 0: 1, 1: 2, length: 2}, 'assign should treat array-like objects like normal objects');
167167
});
168168

underscore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@
10001000

10011001
// Assigns a given object with all the own properties in the passed-in object(s)
10021002
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
1003-
_.extendOwn = createAssigner(_.keys);
1003+
_.assign = _.extendOwn = createAssigner(_.keys);
10041004

10051005
// Returns the first key on an object that passes a predicate test
10061006
_.findKey = function(obj, predicate, context) {

0 commit comments

Comments
 (0)