先举1个例子:

  

<input type="text" value="ssd" id="mytest" />

 

 var value = "gloss";
 
function getvalue(){
     
this.value = "ss"
 }
 
 
function getPress(){
    alert(
this.value);
 }
 
getPress.call(
new getvalue());
getPress.call(document.getElementById(
'mytest'));
getPress.call(window);

 

 其实call()就是改变getPress对象的上下文 替换为call 中的第一个参数

而apply和call效果是一样的

要说区别呢主要体现在传入参数上

  call第二个参数开始按次序传入参数  而 apply的参数从第二个开始 作为一个数组传入

 

 

 

相关文章:

  • 2021-01-16
  • 2019-11-14
  • 2019-11-18
  • 2019-03-14
  • 2019-06-27
  • 2020-06-11
  • 2019-11-26
  • 2021-09-14
猜你喜欢
  • 2019-07-10
  • 2019-07-21
  • 2019-10-27
  • 2020-01-03
  • 2018-04-13
  • 2018-04-10
  • 2021-12-04
  • 2021-03-10
相关资源
相似解决方案