You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
707 B
29 lines
707 B
var keys = require('./keys')
|
|
|
|
var slice = require('./slice')
|
|
var includes = require('./includes')
|
|
var arrayEach = require('./arrayEach')
|
|
|
|
var assign = require('./assign')
|
|
|
|
/**
|
|
* 将一个或者多个对象值解构到目标对象
|
|
*
|
|
* @param {Object} destination 目标对象
|
|
* @param {...Object}
|
|
* @return {Boolean}
|
|
*/
|
|
function destructuring (destination, sources) {
|
|
if (destination && sources) {
|
|
var rest = assign.apply(this, [{}].concat(slice(arguments, 1)))
|
|
var restKeys = keys(rest)
|
|
arrayEach(keys(destination), function (key) {
|
|
if (includes(restKeys, key)) {
|
|
destination[key] = rest[key]
|
|
}
|
|
})
|
|
}
|
|
return destination
|
|
}
|
|
|
|
module.exports = destructuring
|
|
|