1
This commit is contained in:
25
20220330_Vote/Ewide.Web.Entry/wwwroot/lib/xe-utils/map.js
Normal file
25
20220330_Vote/Ewide.Web.Entry/wwwroot/lib/xe-utils/map.js
Normal file
@@ -0,0 +1,25 @@
|
||||
var each = require('./each')
|
||||
|
||||
/**
|
||||
* 指定方法后的返回值组成的新数组
|
||||
*
|
||||
* @param {Object} obj 对象/数组
|
||||
* @param {Function} iterate(item, index, obj) 回调
|
||||
* @param {Object} context 上下文
|
||||
* @return {Array}
|
||||
*/
|
||||
function map (obj, iterate, context) {
|
||||
var result = []
|
||||
if (obj && arguments.length > 1) {
|
||||
if (obj.map) {
|
||||
return obj.map(iterate, context)
|
||||
} else {
|
||||
each(obj, function () {
|
||||
result.push(iterate.apply(context, arguments))
|
||||
})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = map
|
||||
Reference in New Issue
Block a user