zoukankan      html  css  js  c++  java
  • js显示对象所有属性和方法的函数

    function ShowObjProperty2( obj ) { 
        // 用来保存所有的属性名称和值 
        var attributes = '' ; 
        var methods = ''
        // 开始遍历 
        for ( var p in obj ){ 
            // 方法 
            if ( typeof( obj[p] ) === "function" ){ 
                attributes += '属性:' + p + '
    '
                // obj[p](); 
            } else { 
                // p 为属性名称,obj[p]为对应属性的值 
                methods += '方法:' + p + " = " + obj[p] + "
    " ; 
            } 
        } 
        // 最后显示所有的属性 
        return attributes, methods
    }
    function ShowObjProperty1(Obj) 
    { 
        var attributes = ''; 
        var methods = ''; 
        for(const attr in Obj){ 
            if(Obj.attr != null) 
                attributes = attributes + attr + ' 属性: ' + Obj.i + '
    ' ; 
        else 
            methods = methods + '方法: ' + attr + '
    '; 
        } 
        return attributes, methods 
    }     
  • 相关阅读:
    2017.11.20
    第8次
    作业 lianxi
    java 7个练习题
    java 2.15
    java 2.6
    jsp变量和方法的声明
    jsp 基本标签从头练习
    15
    14
  • 原文地址:https://www.cnblogs.com/spaceapp/p/10334521.html
Copyright © 2011-2022 走看看