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.
25 lines
553 B
25 lines
553 B
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
|
|
|