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方法了