We have probably been confronted with situations where we have to assign multiple properties to the same object, as shown in the following example:
person.name = values[0]; person.age = values[1]; person.job = values[2];
In the preceding example, there are only three properties, but when we have more, it becomes kind of tedious to write object.property = value
each time. There is a better way to do this: by using the xtend
module (https://www.npmjs.org/package/xtend):
var xtend = require('xtend'); person = xtend(person, { name: values[0], age: values[1], job: values[2] });
The preceding code looks much cleaner, doesn't it?
These properties from an object (the source) are merged into another object (the target). This approach enables us to use mixins efficiently and in an elegant manner.