Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

var arr = [3, 10, 2, 100];
var max = Math.max.apply(Math, arr);

console.log(max);  //  100

有大神能详细讲解一下吗,小白弄不懂


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
141 views
Welcome To Ask or Share your Answers For Others

1 Answer

如何改变指针是标准定的,apply和call就是用来改变作用域的

call与apply的区别在于前者的参数是一个一个的,比如:

var max = Math.max;
var a = max.call(Math,1,2,5,8);
alert(a)  //8
var max=Math.max
var a=max.apply(Math,[1,2,5,8]);
alert(a)  //8

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...