//定义父类
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求达人解决方案....

解决方案 »

  1.   

    for(i in new InputRadio()){
     alert(i);//i就是test的属性名
     }
      

  2.   

    这样prefix,constructor,foo也会弹出....不知道怎么排除这几个
      

  3.   


    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);
    }
      

  4.   

    可以了,原来是多加了InputText.call(this);刚才没看清楚~~~
      

  5.   

            //定义父类
            function InputText() {
                this.prefix = new Function("alert(InputText_)");
            }
            //表单元素的前缀名称
            InputText.prototype.id = '';
            InputText.prototype.name = '';
            InputText.prototype.type = { 'text': 'text', 'password': 'password', 'hidden': 'hidden' };        //定义子类
            function InputRadio() {
            }
            //定义子类
            InputRadio.prototype.checked = { 'false': 'false', 'true': 'true' };        //支持Object.keys()这种方法的浏览器有IE9+、Firefox4+、Safari5+、Opera12+、Chrome
            var keys1 = Object.keys(InputText.prototype);
            var keys2 = Object.keys(InputRadio.prototype);
            alert(keys1+','+keys2);