1.在数组的原型上定义一个升序的方法
var a=[4,3,2,1];Array.prototype.mysort=function(event){if(Array.isArray(event)){return event.sort((a,b)=>a-b);}}console.log(a.mysort(a));//输出 [1,2,3,4]
2.在数组的原型上定义一个求和的方法
var b=[4,3,2,1];Array.prototype.sum=function(params){if(Array.isArray(params)){return params.reduce((a,b)=>a+b);}}console.log(b.sum(b));//输出10
3.在数组原型挂载一个http方法
<script>Array.prototype.http=function(){console.log("http");}var obj=[1,2,3]obj.http()</script>
