应用对象-this-slice-函数的call,apply:将非数组变为数组

    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
<script>
    class Arrays{
           constructor(){

           }
           slice(start,end){
            //    console.log(this);
              if(start<0) start=this.length+start;
              if(end<0) end=this.length+end;
              if(start===undefined) start=0;
              if(end===undefined) end=this.length;
              var a=[];
                for(var i=start;i<end;i++){
                    a.push(this[i]);
                }
                return a;
           }
       }

  

       var divs=document.getElementsByTagName("div");
       arr=[].slice.call(divs);
       console.log(arr);
    
</script>

应用对象-this-slice-函数的call,apply:将非数组变为数组

上一篇:axios删除接口


下一篇:Android移动开发——图像绘制技术(自定义组件)