How to use the method of copying object properties with their attributes?

Now I read the Flanagan. Came across a very useful script, but I don't know how to use it with code to copy properties of the object(including its attributes). Give a simple example, please! (code below)

Example 6.3. Copy attributes properties
/*
* Adds a non-enumerable method extend() to Object.prototype.
* This method expands the objects to copy properties from an object
* passed in the argument. This method copies not only the value of the properties
* but all their attributes. Object to the argument copies all its own
* properties (even unavailable for transfer), with the exception of the same name
* properties contained in the current object.
*/
Object.defineProperty(Object.prototype
"extend", // Object is Defined.prototype.extend
{
writable: true,
enumerable: false, // Make non-enumerable
configurable: true,
value: function(o) { // property Value is the function
// Get all own properties, even non-enumerable
var names = Object.getOwnPropertyNames(o);
// To bypass them in the loop
for(var i = 0; i < names.length; i++) {
// Skip properties that already exist in this object
if (names[i] in this) continue;
// Get the property descriptor of o
var desc = Object.getOwnPropertyDescriptor(o,names[i]);
// To create the property in this object
Object.defineProperty(this, names[i], desc);
}
}
});
June 8th 19 at 17:01
1 answer
June 8th 19 at 17:03
const a = { one: 1 }
const b = { ...a }
TH :-| ? - Dell_Brown commented on June 8th 19 at 17:06
showed you an example of how in the modern world, copying objects.
don't know what you mean by the "attributes" because it's not html, it's just key-value - hailee commented on June 8th 19 at 17:09
the attributes of object properties or keys of descriptors.
https://developer.mozilla.org/ru/docs/Web/JavaScri... - Willard_Jerde67 commented on June 8th 19 at 17:12

Find more questions by tags JavaScript