Javascript Array arrMap(fn, context)

Description

Javascript Array arrMap(fn, context)

Array.prototype.arrMap = function (fn, context) { // ??IE9??
    context = context || window;/*from  w  ww.j  a v a  2s  .  com*/
    var ary = [];
    if (Array.prototype.map) {
        ary = this.map(fn, context);
    } else {
        for (var i = 0; i < this.length; i++) {
            ary[i] = fn.apply(context, [this[i], i, this]);
        }
    }
    return ary;
}



PreviousNext

Related