]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Object.assign(), described in E6 Section 19.1.2.1 | |
3 | * | |
4 | * http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.assign | |
5 | */ | |
6 | ||
7 | if (typeof Object.assign === 'undefined') { | |
8 | Object.defineProperty(Object, 'assign', { | |
9 | value: function (target) { | |
10 | var i, n, j, m, k; | |
11 | var source, keys; | |
12 | var gotError; | |
13 | var pendingError; | |
14 | ||
15 | if (target == null) { | |
16 | throw new Exception('target null or undefined'); | |
17 | } | |
18 | ||
19 | for (i = 1, n = arguments.length; i < n; i++) { | |
20 | source = arguments[i]; | |
21 | if (source == null) { | |
22 | continue; // null or undefined | |
23 | } | |
24 | source = Object(source); | |
25 | keys = Object.keys(source); // enumerable own keys | |
26 | ||
27 | for (j = 0, m = keys.length; j < m; j++) { | |
28 | k = keys[j]; | |
29 | try { | |
30 | target[k] = source[k]; | |
31 | } catch (e) { | |
32 | if (!gotError) { | |
33 | gotError = true; | |
34 | pendingError = e; | |
35 | } | |
36 | } | |
37 | } | |
38 | } | |
39 | ||
40 | if (gotError) { | |
41 | throw pendingError; | |
42 | } | |
43 | }, writable: true, enumerable: false, configurable: true | |
44 | }); | |
45 | } |