@@ -46,26 +46,38 @@ function validate_(params) {
4646}
4747
4848/**
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/
5859 */
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' ) ;
6366 }
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+ }
6779 }
68- return destination ;
80+ return to ;
6981}
7082
7183/**
0 commit comments