2017-02-28 00:54:18 +08:00
|
|
|
/**
|
2018-05-25 00:38:52 +08:00
|
|
|
*
|
2017-02-28 00:54:18 +08:00
|
|
|
* @authors yutent (yutent@doui.cc)
|
|
|
|
* @date 2017-02-27 18:02:56
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-05-25 00:38:52 +08:00
|
|
|
'use strict'
|
2017-02-28 00:54:18 +08:00
|
|
|
|
|
|
|
// 对象合并
|
2018-05-25 00:38:52 +08:00
|
|
|
if (!Object.prototype.merge) {
|
|
|
|
Object.defineProperty(Object.prototype, 'merge', {
|
|
|
|
value: function() {
|
|
|
|
let args = Array.from(arguments)
|
|
|
|
if (args.length < 1 || typeof args[0] !== 'object') {
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
args.unshift(this)
|
|
|
|
|
|
|
|
Object.assign.apply(null, args)
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
enumerable: false,
|
|
|
|
writable: true
|
|
|
|
})
|
2017-02-28 00:54:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [ 判断对象/数组是否为空]
|
|
|
|
* eg.
|
|
|
|
* Object.empty(obj/arr)
|
|
|
|
*/
|
2018-05-25 00:38:52 +08:00
|
|
|
if (!Object.empty) {
|
|
|
|
Object.defineProperty(Object, 'empty', {
|
|
|
|
value: function(obj) {
|
|
|
|
try {
|
|
|
|
for (let i in obj) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
enumerable: false
|
|
|
|
})
|
2017-02-28 00:54:18 +08:00
|
|
|
}
|