forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject-assign.js
More file actions
45 lines (40 loc) · 1.32 KB
/
object-assign.js
File metadata and controls
45 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Object.assign(), described in E6 Section 19.1.2.1
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.assign
*/
if (typeof Object.assign === 'undefined') {
Object.defineProperty(Object, 'assign', {
value: function (target) {
var i, n, j, m, k;
var source, keys;
var gotError;
var pendingError;
if (target == null) {
throw new Exception('target null or undefined');
}
for (i = 1, n = arguments.length; i < n; i++) {
source = arguments[i];
if (source == null) {
continue; // null or undefined
}
source = Object(source);
keys = Object.keys(source); // enumerable own keys
for (j = 0, m = keys.length; j < m; j++) {
k = keys[j];
try {
target[k] = source[k];
} catch (e) {
if (!gotError) {
gotError = true;
pendingError = e;
}
}
}
}
if (gotError) {
throw pendingError;
}
}, writable: true, enumerable: false, configurable: true
});
}