es.shim/lib/object.js

46 lines
805 B
JavaScript
Raw Normal View History

2017-02-28 00:54:18 +08:00
/**
*
2017-02-28 00:54:18 +08:00
* @authors yutent (yutent@doui.cc)
* @date 2017-02-27 18:02:56
*
*/
'use strict'
2017-02-28 00:54:18 +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)
*/
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
}