应用对象-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>
上一篇:删除事件


下一篇:JQuery入门学习(更新中...)