prototype [ˈprəʊtətaɪp] 原型

<script>
Array.prototype.mysort = function(){
    let s = this;
    for(i=0;i<s.length;i++){
        s[i] = parseInt(s[i]) + 1;
    }
    return s;
}

var arr = new Array(6)
arr[0] = "3"
arr[1] = "1"
arr[2] = "4"
arr[3] = "6"
arr[4] = "2"
arr[5] = "3"

console.log(arr.mysort());
</script>

 此时的Array类型就有了一个mysort方法了

posted @ 2018-11-09 09:01  fleam  阅读(335)  评论(0编辑  收藏  举报