应用对象-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>
} 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>
标签:arr,slice,console,start,call,数组,divs 来源: https://www.cnblogs.com/wjsblog/p/12883398.html