Javascript Array indexOf(e,fn)

Description

Javascript Array indexOf(e,fn)


"use strict"//www.j a va2 s.  co  m


Array.prototype.indexOf = function(e,fn) {
    if(!fn) {
        return this.indexOfOld(e)
    } else {
        if (typeof fn ==='string') {
            var att = fn
            fn = function(e) {
                return e[att]
            }
        }
       return this.map(fn).indexOfOld(e);
    }
}
Array.prototype.indexOfOld=Array.prototype.indexOf



PreviousNext

Related