document.write(String.constructor);//function Function() { [native code] } 
document.write(new String().constructor);//function String() { [native code] } 
//反射更是没有数据
   for(temp in String){
document.write(String.prototype[temp]);
   }我是新手,想问下高手大哥大姐们,能否通过类似java反射技术,反射到String,Math,Array等类的属性及方法??
JS做不到么??

解决方案 »

  1.   


    var Test = function() {
        var private = {        testOne : function () {},
            testTwo : function () {},
            testThree : function () {}
        };   
        function getMethods() {
            for (i in this) {
                alert(i); // shows getMethods, but not private methods
                //alert(this[i]);
            }
            for (i in private) {
                alert(i); // private methods
            }
        }
        return { getMethods : getMethods }
    }();
    // will return ['testOne', 'testTwo', 'testThree', 'getMethods']
        Test.getMethods();
      

  2.   

    谢谢了,这是反射自己创建的类..我想知道怎么反射原有的String/Math 这些类???
      

  3.   

    for  in但可能很多看不到的样子
      

  4.   

    给你介绍个最方便的方法,想看什么类就随便new一个出来。然后console.log()打印这个类,用firebug看的一目了然哦。注意,要在firebug里看。..楼上的方法只能看到属性和方法名,但是用class.i打印的是null
      

  5.   

    比起firefox的firebug,我还是喜欢用Chrome自带的控制台
      

  6.   


    大师,请问你那怎么得到的啊??? 急求,方法,步骤,前面那兄弟告诉我用firebug 我没有尝试成功
      

  7.   


    大师不敢当,我只是一个小菜鸟。我用的是google浏览器打印出来的,firefox没有试过。个人不怎么用firefox。
      

  8.   

    数组的打印方法差不多,用console.dir([]);
      

  9.   

    厉害,问题就再firebug
     同样的方法firebug显示不出来.//
      

  10.   

    高手,那你这个是有插件么??
    为什么我google是这样