首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js 获取类属性有关问题

2013-03-22 
js 获取类属性问题//定义父类function InputText() {this.id this.name this.type {text:t

js 获取类属性问题


//定义父类
function InputText() {
    this.id = '';
    this.name = '';
    this.type = {'text':'text','password':'password','hidden':'hidden'};
}
//表单元素的前缀名称
InputText.prototype.prefix = 'InputText_';


//定义子类
 function InputRadio() {
     this.checked = {'false':'false','true':'true'};
 }
 InputRadio.prototype = new InputText();
 InputRadio.prototype.constructor = InputRadio;
 InputRadio.prototype.foo = function () { alert(this.prefix);};

//如何获取子类与父类构造函数里面的属性呢?
结果应该是:id,name,type,checked

求达人解决方案....
[解决办法]

function InputText() {
    this.id = '';
    this.name = '';
    this.type = {'text':'text','password':'password','hidden':'hidden'};
}
//表单元素的前缀名称
InputText.prototype.prefix = 'InputText_';
 
 
//定义子类
 function InputRadio() {
     this.checked = {'false':'false','true':'true'};
     InputText.call(this);
 }
 InputRadio.prototype = new InputText();
 InputRadio.prototype.constructor = InputRadio;
 InputRadio.prototype.foo = function () { alert(this.prefix);};

var a = new InputRadio();
for(i in a){
 a.hasOwnProperty(i) && console.log(i);
}

热点排行