Per Closing Documentation :
Extends an object with another object. It acts "in place"; it does not create a new object. Example: var o = {}; goog.object.extend (o, {a: 0, b: 1}); about; // {a: 0, b: 1} goog.object.extend (o, {b: 2, c: 3}); about; // {a: 0, b: 2, c: 3}
But this is not a functional approach, and for many contexts a functional approach is better. Does Closure offer something more modern for this?
eg.
goog.object.extend(a, b);
becomes
a = goog.object.extend(a, b);
You can create a new object using an empty object literal, which will be expanded with the objects you want to copy-merge:
var x = {}; goog.object.extend(x, a, b); a = x;
, Object.create(Object.getPrototypeOf(a)).
Object.create(Object.getPrototypeOf(a))
:
var a = {}; var b = extend(a, { a: 0, b: 1 }); var c = extend(b, { b: 2, c: 3 }); console.log(a, b, c); function extend(a, b) { var result = {}; for (var x in a) if (a.hasOwnProperty(x)) result[x] = a[x]; for (var x in b) if (b.hasOwnProperty(x)) result[x] = b[x]; return result; }
, .
Source: https://habr.com/ru/post/1691158/More articles:Why do all Recompose recipes start with "const {Component} = React;" - reactjsНужна фоновая картинка для экрана чата для разных соотношений сторон экрана и портретного и ландшафтного режима - flutterVisual Studio Xamarin application: resource not found that matches the specified name: attr 'android: keyboardNavigationCluster' - xamarin.androidIs there a purely functional way to merge objects in JavaScript? - javascriptЯ получаю ошибку, что #import не найден в xcode - iosJQuery.slideToggle не является гладким на столе - javascriptag-grid после обновления с V8 до V15 разбиение на страницы не работает должным образом. Источник данных не выполняется после начальной загрузки - angularjsManaging a Plutus accounting system for multiple models - ruby-on-railsThe second page does not work with codes on the first page - javascriptag-Grid Pagination does not work in version (10.1.0) in Angular 2 - angularAll Articles