关于继承的一点问题(初学者)

[code="js"]代码: [code="ruby"]
com.ext.HelloWorld = Ext.emptyFn;
com.ext.HelloExt = Ext.emptyFn;
Ext.apply(com.ext.HelloWorld.prototype, {
name : "",
sex : "",
print : function() {
alert(String.format("姓名:{0},性别:{1}", this.name, this.sex));
}
});
/* 继承 */
Ext.extend(com.ext.HelloExt, com.ext.HelloWorld, {
age : "11",
print : function() {
alert(String.format("姓名:{0},性别:{1},年龄{2}", this.name, this.sex, this.age));
}
});

/* 测试调用 */

    var method = new com.ext.HelloWorld();
    method.name="张三";
    method.sex="男";
    method.print();


    var _method = new com.ext.HelloExt();
    _method.name="Ext";
    _method.sex="女";
    _method.print();

[/code][/code]

结果都是HelloExt带年龄的方法.不懂为什么

com.ext.HelloWorld = function(){}; //function(){}; 代码创建一个空函数

Ext.emptyFn; //引用 并不是创建空函数
com.ext.HelloWorld = Ext.emptyFn;
com.ext.HelloExt = Ext.emptyFn; 这2个代表都引用的同一个空对象

为验证 代码如下:
Ext.ns("com.ext")
com.ext.HelloWorld = Ext.emptyFn;
com.ext.HelloExt = Ext.emptyFn;

Ext.apply(com.ext.HelloWorld.prototype, {

name : "",

sex : "",

print : function() {

alert(String.format("姓名:{0},性别:{1}", this.name, this.sex));

}

});

/* 继承
Ext.extend(com.ext.HelloExt, com.ext.HelloWorld, {

age : "11",

print : function() {

alert(String.format("姓名:{0},性别:{1},年龄:{2}", this.name, this.sex, this.age));

}

}); */

Ext.apply(com.ext.HelloExt.prototype, {

xxx: "ff"
});

/* 测试调用 */

    var method = new com.ext.HelloWorld();   
    method.name="张三";   
    method.sex="男";  
    method.age="23";   
   // method.print();   
    alert(method.xxx) 

http://www.iteye.com/topic/370591

Ext.ns("com.ext")
com.ext.HelloWorld = function(){};

com.ext.HelloExt = function(){};

//com.ext.HelloWorld = Ext.emptyFn;
//com.ext.HelloExt = Ext.emptyFn;

Ext.apply(com.ext.HelloWorld.prototype, {

name : "",

sex : "",

print : function() {

alert(String.format("姓名:{0},性别:{1}", this.name, this.sex));

}

});

/* 继承 */

Ext.extend(com.ext.HelloExt, com.ext.HelloWorld, {

age : "11",

print : function() {

alert(String.format("姓名:{0},性别:{1},年龄:{2}", this.name, this.sex, this.age));

}

});

/* 测试调用 */

    var method = new com.ext.HelloWorld();   
    method.name="张三";   
    method.sex="男";  
    method.print();   

    var _method = new com.ext.HelloExt();   
    _method.name="Ext";   
    _method.sex="女";   
    _method.print(); 

这样alert 的结果 就是你想要的了

上面alert出来的结果是 ff