当前位置 : 主页 > 大数据 > 区块链 >

prototype [?pr??t?ta?p] 原型

来源:互联网 收集:自由互联 发布时间:2021-06-22
script Array.prototype.mysort = function (){ let s = this ; for (i=0;is.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" consol
<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方法了

网友评论