是否有可能只显示用户定义的功能& Google Chrome控制台中的属性? [英] Is it possible to show only User Defined Functions & Properties in Google Chrome's console?

查看:127
本文介绍了是否有可能只显示用户定义的功能& Google Chrome控制台中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebug中,您可以将DOM选项卡的输出设置为仅显示用户定义的函数和属性。这对于检查是否有对象转义到全局名称空间很有帮助。在Chrome中是否有相同的功能?

解决方案

以下是近似值:

控制台版本:

  var current; 
(当前在窗口中)
{
/ *如果该属性不为空或未定义* /
if(!! window [current])
{
/ *如果构造函数是Function对象* /
if(/Function/.test(String(window[current].constructor)))
{
/ * Print to控制台* /
console.log(current)
}
}
}

Bookmarklet版本:

  javascript:void(function(){for(_ in window){ if(!! window [_]){if(/Function/.test(String(window[_].constructor))){console.log(_)}}}}())

通用版本:

 函数getUDFs()
{
var current;
/ *使用current而不是_来避免创建一个迭代器全局变量* /
(参数[0]中的当前值)
{
/ *如果属性不为null或者未定义* /
if(!! arguments [0] [current])
{
/ *如果构造函数是Function对象* /
if(/ Function / test(String(arguments [0] [current] .constructor)))
{
/ *打印到控制台* /
console.log(current)
}


$ b $ / code $ / pre
$ b $递归版本

 函数getUDFs()
{
var current;
/ *使用current而不是_来避免创建一个迭代器全局变量* /
(参数[0]中的当前值)
{
getUDFs.id = arguments [1] +=>;
/ *如果该属性不为空或未定义* /
if(!! arguments [0] [current])
{
/ *如果构造函数是Function对象* /
if(/Function/.test(String(arguments[0][current].constructor)))
{
/ *打印到控制台* /
console .log(getUDFs.id + current)
}

/ *检查对象属性* /
if(/Object/.test(String(arguments[0][current] .constructor)))
{
getUDFs(arguments [0] [current],getUDFs.id + current)
}

/ *检查原型属性,但跳过构造器原型* /

if(!! arguments [0] [current]&&& arguments [0] [current] .hasOwnProperty(prototype)&&&arguments [0] [current]!== arguments [0] [constructor])
{
getUDFs(arguments [0] [current] [prototype],getUDFs.id + current +=>原型)
}
}
}
}
getUDFs(jQuery,jQuery)

带存储的递归版本:

 函数getUDFs()
{
var current;
$ b $ *使用current而不是_来避免创建一个迭代器全局变量* /

(参数[0]中的当前值)
{
getUDFs.id = arguments [1] +=>;
$ b $ *如果该属性不为空或未定义* /
if(!! arguments [0] [current])
{
/ *如果构造函数是函数对象* /
if(/Function/.test(String(arguments[0][current].constructor)))
{
/ *存储在数组中* / $ (getUDFs.hasOwnProperty(data))
{
getUDFs.data.push(getUDFs.id + current)
}
else
{
getUDFs.data = []
}
}

if(/Object/.test(String(arguments[0][current].constructor)))
{
getUDFs(arguments [0] [current],getUDFs.id + current)
}
}
}
}
getUDFs (jQuery,jQuery)

带取证的递归版本:

 函数getUDFs()
{
var current;
$ b $ *使用current而不是_来避免创建一个迭代器全局变量* /

(参数[0]中的当前值)
{
getUDFs.id = arguments [1] +=>;
$ b $ *如果该属性不为空或未定义* /
if(!! arguments [0] [current])
{
/ *如果构造函数是函数对象* /
if(/Function/.test(String(arguments[0][current].constructor)))
{
/ *存储在数组中* / $ (getUDFs.hasOwnProperty(data))
{
try {getUDFs.data.push(getUDFs.id + current + String()。concat( - args:, (,arguments [0] [current] [length],)))} catch(e){getUDFs.data.push(getUDFs.id + current)};

try {getUDFs.data [getUDFs.data.length-1] + =required:+!arguments [0] [current]()?真正的:false} catch(e){getUDFs.data [getUDFs.data.length-1] + =required:true}
}
else
{
getUDFs。数据= []
}
}

if(参数[0] .hasOwnProperty(current))
{
if(/Object/.test (String(arguments [0] [current] .constructor)))
{
getUDFs(arguments [0] [current],getUDFs.id + current)
}
}
}
}
}
getUDFs(jQuery,jQuery);
getUDFs.data.toString()。replace(,,\ n,g)

参考文献


In Firebug you can set the output of the DOM tab to only show user defined functions and properties. This is helpful for checking if you have objects escaping into the global namespace. Is there an equivalent in Chrome?

解决方案

Here's a close approximation:

Console version:

var current;
for(current in window)
  {
  /* If the property is not null or undefined */
  if (!!window[current] )
    {
    /* If the constructor is the Function object */
    if (/Function/.test(String(window[current].constructor) ) )
      {
      /* Print to the console */
      console.log(current)
      }
    }
  }

Bookmarklet version:

javascript:void(function(){for(_ in window) { if (!!window[_] ) { if (/Function/.test(String(window[_].constructor) ) ) { console.log(_) } } }}())

Generic version:

function getUDFs()
{
var current;
/* Use current instead of _ to avoid creating an iterator global variable */
for(current in arguments[0])
  {
  /* If the property is not null or undefined */
  if (!!arguments[0][current] )
    {
    /* If the constructor is the Function object */
    if (/Function/.test(String(arguments[0][current].constructor) ) )
      {
      /* Print to the console */
      console.log(current)
      }
    }
  }
 }

Recursive version:

function getUDFs()
{
var current;
/* Use current instead of _ to avoid creating an iterator global variable */
for(current in arguments[0])
  {
  getUDFs.id = arguments[1]  + " => ";
  /* If the property is not null or undefined */
  if (!!arguments[0][current] )
    {
    /* If the constructor is the Function object */
    if (/Function/.test(String(arguments[0][current].constructor) ) )
      {
      /* Print to the console */
      console.log(getUDFs.id + current)
      }

    /* Check object properties */
    if (/Object/.test(String(arguments[0][current].constructor) ) )
     {
     getUDFs(arguments[0][current], getUDFs.id + current)
     }

    /* Check prototype properties, but skip constructor prototypes */

    if (!!arguments[0][current] && arguments[0][current].hasOwnProperty("prototype") && arguments[0][current] !== arguments[0]["constructor"])
     {
     getUDFs(arguments[0][current]["prototype"], getUDFs.id + current + " => prototype")
     }
    }
  }  
 }
 getUDFs(jQuery,"jQuery")

Recursive version with storage:

    function getUDFs()
    {
    var current;

     /* Use current instead of _ to avoid creating an iterator global variable */

    for(current in arguments[0])
      {
      getUDFs.id = arguments[1]  + " => ";

      /* If the property is not null or undefined */
      if (!!arguments[0][current] )
        {
        /* If the constructor is the Function object */
        if (/Function/.test(String(arguments[0][current].constructor) ) )
          {
          /* Store in an array */
          if (getUDFs.hasOwnProperty("data") )
            {
            getUDFs.data.push(getUDFs.id + current)
            }
          else
            {
            getUDFs.data = []
            }
          }

        if (/Object/.test(String(arguments[0][current].constructor) ) )
         {
         getUDFs(arguments[0][current], getUDFs.id + current)
         }
        }
      }  
     }
     getUDFs(jQuery,"jQuery")    

Recursive version with forensics:

function getUDFs()
{
var current;

 /* Use current instead of _ to avoid creating an iterator global variable */

for(current in arguments[0])
  {
  getUDFs.id = arguments[1]  + " => ";

  /* If the property is not null or undefined */
  if (!!arguments[0][current] )
    {
    /* If the constructor is the Function object */
    if (/Function/.test(String(arguments[0][current].constructor) ) )
      {
      /* Store in an array */
      if (getUDFs.hasOwnProperty("data") )
        {
        try{getUDFs.data.push(getUDFs.id + current + String().concat("- args: ","(", arguments[0][current]["length"], ")"))}catch(e){getUDFs.data.push(getUDFs.id + current)};

        try{getUDFs.data[getUDFs.data.length-1] += "required:" + !arguments[0][current]() ? true: false}catch(e){getUDFs.data[getUDFs.data.length-1] += "required: true"}
        }
      else
        {
        getUDFs.data = []
        }
      }

    if (arguments[0].hasOwnProperty(current) )
      {
      if (/Object/.test(String(arguments[0][current].constructor) ) )
        {
        getUDFs(arguments[0][current], getUDFs.id + current)
        }
      }
    }
  }  
 }
 getUDFs(jQuery,"jQuery");
 getUDFs.data.toString().replace(",","\n","g") 

References

这篇关于是否有可能只显示用户定义的功能& Google Chrome控制台中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆