Javascript中的 对象步骤(实例方法),类方法,原型方法

Javascript中的 对象方法(实例方法),类方法,原型方法。
<script>
function Base(){
// 实例方法
this.sayMe = function(){
alert('base::sayMe');
}
}

function Sub(){
//实例方法
//this.sayMe = function(){
//alert('sub::sayMe');
//}
}


Sub.prototype = new Base();

//原型方法
Sub.prototype.sayMe = function(){
alert('sub1');
}

//原型方法
//Sub.prototype.sayMe = function(){
//alert('sub2');
//}
var sub = new Sub();
sub.sayMe();  // sub::sayMe  
//说明:方法查找顺序: 原型方法 〉 实例方法 〉继承来的方法(父类实例作为子类原型继承到的方法)。
//原型后来的方法覆盖先前的方法

</script>



关于call()的用法:

<script>
function B(){
this.f = function(){
alert('B.f');
}

this.g = function(){
alert('B.g');
}

}

B.f = function(){
alert('B.static.f');
}

function C(){
this.f = function(){
alert('C.f');
}
}

C.f = function(){
alert('C.static.f');
}

C.prototype= new B();
var b = new B();
var c = new C();
c.f();  // C.f   调用子类的实例方法。(子类也有同样的方法)
c.g();  // B.g调用父类的实例方法。(子类没有)
b.f.call(c); // B.f  调用父类的实例方法 (子类也有同样的方法)
B.f.call(c); // B.static.f 调用父类的类方法。
B.f.call(C); // B.static.f 调用父类的类方法。
try{
B.g.call(c); // typeerror: can not read property 'call' of undefined. 因为 B没有类方法 g, 他只是实例方法 g.
}catch(e){
alert(e);}
C.f(); // C.static.f 调用子类的类方法。
C.f.call(b);//C.static.f 调用子类的类方法。
</script>