Files
number_zj/20220330_Vote/Ewide.Web.Entry/wwwroot/lib/xe-utils/map.js
毛财君 197b38ca6f 1
2023-07-06 17:37:33 +08:00

26 lines
553 B
JavaScript

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