当前位置 : 主页 > 编程语言 > java >

前端学习案例-重写foreach

来源:互联网 收集:自由互联 发布时间:2022-09-02
!DOCTYPE html html lang = "en" head meta charset = "UTF-8" meta http-equiv = "X-UA-Compatible" content = "IE=edge" meta name = "viewport" content = "width=device-width, initial-scale=1.0" title 重写foreach / title / head body script Array
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>重写foreach</title>
</head>
<body>
<script>
Array.prototype.foreach=function(cb){
const _arr=this
var _len=_arr.length
var _arg2=arguments[1]||window
for(var i=0;i<_len;i++){
cd.apply(_arg2,[_arr[i],i,_arr])
}
}
</script>
</body>
</html>



网友评论