3

Firebug では、ユーザー定義の関数とプロパティのみを表示するように DOM タブの出力を設定できます。これは、オブジェクトがグローバル名前空間にエスケープされているかどうかを確認するのに役立ちます。Chromeに同等のものはありますか?

4

1 に答える 1

0

近似値は次のとおりです。

コンソール版:

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

ブックマークレットのバージョン:

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

一般的なバージョン:

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

再帰バージョン:

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")

ストレージ付きの再帰バージョン:

    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")    

フォレンジックを使用した再帰バージョン:

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") 

参考文献

于 2013-08-26T21:05:49.580 に答える