• 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 
    }
    

      

  • 相关阅读:
    省选测试13
    省选测试12
    省选测试11
    省选测试9
    省选测试10
    省选测试8
    省选测试7
    省选测试6
    倍增 LCA && ST表
    博客园markdown
  • 原文地址:https://www.cnblogs.com/front-girl/p/11655136.html
Copyright © 2020-2023  润新知