function a() { this.b = "b"; }
function b() { this.a = "a" }
function c() { this.c = "c"; }
b.prototype = new a();//prototype 可以向其原型动态添加功能(方法和属性)。b继承a,b的constructor 被改变为a,那么当new b的时候new 的是哪个constructor?a的还是b的? b的,prototype 保存的只是b函数的一个引用,不是b原型本身,而是b原型的一部分(prototype在javascript中是所有function的一个属性,里面记载着function和function的constructor),
//b.prototype.constructor = b;
//b extend a, constructor change a;
c.prototype = new b();
//c.prototype.constructor = c;
var c1 = new c();
document.writeln(c.prototype.constructor);
c.call(a);//相当于a继承c ,另一种说法就是把c 函数的 this=a了(c 函数中的this被指向 a 函数)。
//上面这局做了三件事,一 : 初始化了c, 二: 替换this指向,////三:调用c。
</script>
例子---
<script>
function a() {
this.a = "a";
this.show = function () { alert(this + this.a + "dddd"); return this.a;}
/// alert("dddd");
alert(this);
alert(this+" yiyyy "+this.show());
alert(this);
}
function b() { this.b = "b" }
function c() { alert(this); this.g = "c"; alert(this); alert(g); }
// b.prototype = new a();
// b.prototype.constructor = b;
//b extend a, constructor change a;
//c.prototype = new b();
//c.prototype.constructor = c;
// var c1 = new c();
// a.prototype = b.prototype;
// document.writeln(b.prototype.a);
a.call(c);
</script>