源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

实现连缀调用的map方法(prototype)

  • 时间:2022-06-29 17:46 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:实现连缀调用的map方法(prototype)
[u]复制代码[/u] 代码如下:
<script type="text/javascript"> function SpecialArray(arr){ this.arr=arr; } SpecialArray.prototype.map=function(func){ for(var i=0,len=this.arr.length;i<len;i++){ this.arr[i]=func(this.arr[i]); //调用函数,改变arr数组的每个项的值 } return this; //返回自身对象 } var obj=new SpecialArray([ a , b , c ]); //可以对obj的arr属性做任何的操作 alert(obj.map(function(el){return el.toUpperCase()}).arr); alert(obj.map(function(el){return el+"!";}).arr); </script>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部