Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

apply方法如何改变this指针的?

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

console.log(max);  //  100

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


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

1 Answer

0 votes
by (71.8m points)

如何改变指针是标准定的,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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...