Quoting all elements in a window object

Last night I got really bored, and I thought a little about a small script. Basically, I thought about how many built-in PHP functions compared to JavaScript, and then I realized that I really don't know how many functions JavaScript actually has. I was thinking of writing a script that would look at a window object, including every object inside the object, etc. I wrote a script and it worked (tried it on a smaller object).

However, my problem is that JavaScript will not let me loop into the whole Windows object.

I tried:

for (var key in window) { console.log(key); } 

I also tried:

 var a = Object.create(window); for (var key in a) { console.log(key); } 

Both code snippets give me:

 top window location external chrome Intl v8Intl document script1374438467163 $pick $try IFrame Elements OverText IframeShim Mask Clientcide dbug value debugCookie StyleWriter StickyWin TabSwapper Collapsible Collapsable Drag Cookie Accordion Asset Spinner MultipleOpenAccordion MooTools typeOf instanceOf Type Hash Native $A $arguments $chk $clear $defined $each $empty $extend $H $merge $lambda $mixin $random $splat $time $type $unlink Browser $constructor Window $family Document $exec Slick Element uniqueNumber $ getDocument getWindow Selectors $$ addListener removeListener retrieve store eliminate Class Chain Events Options Request DOMEvent Event addEvent removeEvent addEvents removeEvents fireEvent cloneEvents Fx Swiff getSize getScroll getScrollSize getPosition getCoordinates getHeight getWidth getScrollTop getScrollLeft getScrollHeight getScrollWidth getTop getLeft setCNETAssetBaseHref Table BehaviorAPI Behavior Color $RGB $HSB $HEX Keyboard Locale URI CodeMirror JSHINT _ emmet Sidebar keyMods Layout MooShellActions Base64 Dropdown editorsModified Track update_resource_input remove_resource prepareToSubmit submit_external_resource change_default_input_value validate warn disallowedPlatforms default_code_mirror_options MooShellEditor MooShellSettings disqus_developer disqus_identifier disqus_title csspath jspath imgpath mediapath codemirrorpath panel_html panel_css panel_js makefavouritepath example_server username static_hash csrfToken mooshell preload_resources DP resources default_text add_external_resource_url _gaq TowTruckConfig_enableAnalytics TowTruckConfig_cloneClicks TowTruck _gat gaGlobal style_html css_beautify js_beautify Beautifier language Heyoffline page_test i a key webkitNotifications localStorage sessionStorage applicationCache indexedDB webkitIndexedDB webkitStorageInfo CSS performance console devicePixelRatio styleMedia parent opener frames self defaultstatus defaultStatus status name length closed pageYOffset pageXOffset scrollY scrollX screenTop screenLeft screenY screenX innerWidth innerHeight outerWidth outerHeight offscreenBuffering frameElement crypto clientInformation navigator toolbar statusbar scrollbars personalbar menubar locationbar history screen postMessage close blur focus ondeviceorientation ontransitionend onwebkittransitionend onwebkitanimationstart onwebkitanimationiteration onwebkitanimationend onsearch onreset onwaiting onvolumechange onunload ontimeupdate onsuspend onsubmit onstorage onstalled onselect onseeking onseeked onscroll onresize onratechange onprogress onpopstate onplaying onplay onpause onpageshow onpagehide ononline onoffline onmousewheel onmouseup onmouseover onmouseout onmousemove onmousedown onmessage onloadstart onloadedmetadata onloadeddata onload onkeyup onkeypress onkeydown oninvalid oninput onhashchange onfocus onerror onended onemptied ondurationchange ondrop ondragstart ondragover ondragleave ondragenter ondragend ondrag ondblclick oncontextmenu onclick onchange oncanplaythrough oncanplay onblur onbeforeunload onabort getSelection print stop open showModalDialog alert confirm prompt find scrollBy scrollTo scroll moveBy moveTo resizeBy resizeTo matchMedia setTimeout clearTimeout setInterval clearInterval requestAnimationFrame cancelAnimationFrame webkitRequestAnimationFrame webkitCancelAnimationFrame webkitCancelRequestAnimationFrame atob btoa addEventListener removeEventListener captureEvents releaseEvents getComputedStyle getMatchedCSSRules webkitConvertPointFromPageToNode webkitConvertPointFromNodeToPage dispatchEvent webkitRequestFileSystem webkitResolveLocalFileSystemURL openDatabase TEMPORARY PERSISTENT 

However, I know that there are many more properties inside the Windows object. For example, all SVG functions and HTML functions. Why does JavaScript skip many properties of an object?

+6
source share
1 answer

In modern browsers Object.getOwnPropertyNames() and Object.getPrototypeOf() you can get all the properties of all objects in the prototype chain.

http://jsfiddle.net/FtVXN/

 var obj = window; do Object.getOwnPropertyNames(obj).forEach(function(name) { console.log(name); }); while(obj = Object.getPrototypeOf(obj)); 

If you want to see the separation of prototype objects, add a line that provides a separator.

http://jsfiddle.net/FtVXN/1/

 var obj = window; do { Object.getOwnPropertyNames(obj).forEach(function(name) { console.log(name); }); console.log("============================="); } while(obj = Object.getPrototypeOf(obj)); 

I really think that I remember that in Firefox some globals do not appear until you get them. You may need to experiment a bit if you find this to be the case.

+4
source

Source: https://habr.com/ru/post/949949/


All Articles