先举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-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2021-06-29
  • 2022-01-27
  • 2021-08-11
  • 2021-11-06
  • 2021-12-12
相关资源
相似解决方案