javascript 写一个 map方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    Array.prototype.map = function(fn){
        for (i=0;i<this.length;i++){
          v = this[i];
          k = i;
          fn(v,k,this)
        }

    }
//      console.log(Array.prototype.map);
    var arr = [111,222,333];
    arr.map(function(v,k){
        console.log(v,k)
    })
</script>
</body>
</html>

 

posted @ 2019-05-31 11:34  奔跑的太阳花  阅读(485)  评论(0编辑  收藏  举报