继承

2015-04-11  本文已影响0人  sx_summer

Function类型

  1. 函数的定义
  2. 函数的内部属性
  1. 属性
    prototype
  2. 方法
    apply(),call():在特定的作用域中调用函数
function add(n1,n2){
    debugger;
    console.log(this);
    alert( n1 + n2 );
}

function sub(n1,n2){
    debugger;
    console.log(this);
    alert( n1 - n2 );
}
add.call(sub,1,2);

在sub的作用域中调用add方法,实际上是改变了this的值。使sub继承了add的所有方法和属性。所以 console.log(this) 中的this是sub方法
值为3, 是因为调用的是add的call属性.debugger会进add方法

上一篇 下一篇

猜你喜欢

热点阅读