<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
var arr = [2, 3, 1, 5, 4];
console.log(Math.max.apply(null, arr))
console.log(Math.max.call(null, 1, 2, 3, 4, 5)) //==> Math.max()
console.log(Math.max.call(null, 1, 2, 3));
// [2,3,1,5,4]
// Math.max(2,3,1,5,4) ==> Math.max.apply(null,arr)
// null ==> window
// ; // 5
function test() {
// 检测arguments是否为Array的实例
console.log(
arguments instanceof Array, //false
Array.isArray(arguments) //false
);
// 判断arguments是否有forEach方法
console.log(arguments.forEach); //undefined
console.log(arguments);
// 将数组中的forEach应用到arguments上
Array.prototype.forEach.call(arguments, function(item) {
console.log(item); // 1 2 3 4
});
}
test(1, 2, 3, 4);
</script>
</html>
apply - call 调用非数组方法 Math.max forEach
最新推荐文章于 2021-10-29 09:29:02 发布