@@ -46,26 +46,38 @@ function validate_(params) {
46
46
}
47
47
48
48
/**
49
- * Copy all of the properties in the source objects over to the
50
- * destination object, and return the destination object.
51
- * @param {Object } destination The combined object.
52
- * @param {Object } source The object who's properties are copied to the
53
- * destination.
54
- * @returns {Object } A combined object with the desination and source
55
- * properties.
56
- * @private
57
- * @see http://underscorejs.org/#extend
49
+ * Polyfill for Object.assign, which isn't available on the legacy runtime.
50
+ * Not assigning to Object to avoid overwriting behavior in the parent
51
+ * script(s).
52
+ * @param {Object } target The target object to apply the sources’ properties to,
53
+ * which is returned after it is modified.
54
+ * @param {...Object } sources The source object(s) containing the properties you
55
+ * want to apply.
56
+ * @returns {Object } The target object.
57
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill }
58
+ * @license Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
58
59
*/
59
- function extend_ ( destination , source ) {
60
- // Use Object.assign from the v8 engine, if available.
61
- if ( Object . assign ) {
62
- return Object . assign ( destination , source ) ;
60
+ function assign_ ( target , varArgs ) {
61
+ if ( typeof Object . assign === 'function' ) {
62
+ return Object . assign . apply ( null , arguments ) ;
63
+ }
64
+ if ( target === null || target === undefined ) {
65
+ throw new TypeError ( 'Cannot convert undefined or null to object' ) ;
63
66
}
64
- var keys = Object . keys ( source ) ;
65
- for ( var i = 0 ; i < keys . length ; ++ i ) {
66
- destination [ keys [ i ] ] = source [ keys [ i ] ] ;
67
+ var to = Object ( target ) ;
68
+ for ( var index = 1 ; index < arguments . length ; index ++ ) {
69
+ var nextSource = arguments [ index ] ;
70
+
71
+ if ( nextSource !== null && nextSource !== undefined ) {
72
+ for ( var nextKey in nextSource ) {
73
+ // Avoid bugs when hasOwnProperty is shadowed
74
+ if ( Object . prototype . hasOwnProperty . call ( nextSource , nextKey ) ) {
75
+ to [ nextKey ] = nextSource [ nextKey ] ;
76
+ }
77
+ }
78
+ }
67
79
}
68
- return destination ;
80
+ return to ;
69
81
}
70
82
71
83
/**
0 commit comments