1. 直接使用数学函数
const max = Math.max(1,2,3)
console.log(max) // 3
2. apply
const arr= [ 100 , 60 , 82 ]
const max = Math.max.apply(Math , arr) //此处“Math”可写null,但是不能为空
const min = Math.min.apply(null , arr )
console.log(max) // 100
console.log(min) // 82
apply最基本的语法
const obj = {
age : 18
}
function fn(x ,y ){
console.log(this) // {age:18}
console.log(x + y)
}
// 1. 调用函数
// 2. 改变this指向
// fn.apply(this指向谁,数组参数)
fn.apply(obj , [1,2])
// 3. 返回值 本身技术在调用函数,所以返回值就是函数的返回值
3. 展开运算符
const arr= [ 100 , 60 , 82 ]
console.log( Math.max(...arr) ) // 100