Javascript遍曆DOM結構和對象結構

來源:互聯網
上載者:User

在實際工作中,記住瀏覽器中對象的屬性、方法幾乎是件不可能完成的任務,保持一份資料或網址是個好辦法。但是查閱資料也是要花費不少時間,如果能有個指令碼將對象的結構列印出來,將會加速開發進程。

下面是我編寫的查看對象結構例子,請下載附件擷取可執行代碼:

//Animal是一個對象     Animal = {         createNew: function( bundle ) {             var animal = {};             var protect = bundle || {};//bundle傳遞的是指標,修改protect時外面對象會跟著變(除非不傳)             protect.sound = 'growl';             protect.makeSound = function(){                  return protect.sound;              }             return animal;         }     }             //Cat也是一個對象     Cat = {         pubVar:"Cat",         createNew: function(mySound) {             var protect = {};             var cat = Animal.createNew( protect );//protect會被修改,然後返回空白對象{}給cat             protect.sound = mySound;             cat.meow = function(){ return protect.makeSound(); };//cat要調用protect中的方法             return cat;         }     }               //javascript區分大小寫,通過Cat物件建構一個新的對象賦值給cat     var cat = Cat.createNew("meow!");     var bigCat = Cat.createNew("meow!meow!meow!");             showObject("Cat");     showObject("cat");     showObject("bigCat");
調試資訊:

[Object] Cat
|--[function] createNew = function(mySound) { var protect = {}; var cat = Animal.createNew( protect );//protect會被修改,然後返回空白對象{}給cat protect.sound = mySound; cat.meow = function(){ return protect.makeSound(); };//cat要調用protect中的方法 return cat; }
|--[string] pubVar = Cat

[Object] cat
|--[function] meow = function(){ return protect.makeSound(); }

[Object] bigCat
|--[function] meow = function(){ return protect.makeSound(); }

[備忘1]遍曆DOM結構類似,例如後面將寫一篇博文展示一下IE10的window對象。具體就是在IE10中執行showObject("window");

[備忘2]object類型有下鑽連結,但是有個小問題:不能回退,此時建議按F5鍵。

本文出自 “iData” 部落格,請務必保留此出處http://idata.blog.51cto.com/4581576/1103408

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.