function CBaseClass()
{
this.foo = function(){ alert( 'this is baseclass foo' ); };
this.foo1 = function() { alert( ' this is baseclass foo1' ); };
} function CSubClass()
{
this.sup = new CBaseClass();
// this.super(); this.foo() = function()
{
this.sup.foo();//调用父类的函数,再处理本类的函数
alert( 'this is subclass foo' );
}
this.foo1=this.sup.foo1;
} function main()
{
var obj = new CSubclass();
obj.foo();//调用了子类的foo
obj.foo1();//调用了父类的foo1
}
{
this.foo = function(){ alert( 'this is baseclass foo' ); };
this.foo1 = function() { alert( ' this is baseclass foo1' ); };
} function CSubClass()
{
this.sup = new CBaseClass();
// this.super(); this.foo() = function()
{
this.sup.foo();//调用父类的函数,再处理本类的函数
alert( 'this is subclass foo' );
}
this.foo1=this.sup.foo1;
} function main()
{
var obj = new CSubclass();
obj.foo();//调用了子类的foo
obj.foo1();//调用了父类的foo1
}
-->>
this.foo = function()
这里使用了类聚合 而不是类继承,和我所想功能有点差别
虽然微软提倡使用类聚合,不使用类继承,
为了不反复输入 -->this.foo1=this.sup.foo1;(也许一个类里有几十个函数接口)
还是想看看JS里类继承是怎么实现的