List functions of JavaScript objects?

I want to list all the available functions of various JavaScript objects and even HTML elements created in JavaScript. For example, the following works great in both Chrome and FireFox:

<html> <body> <script> var object = document.createElement( "select" ); for( var prop in object ) { document.body.innerHTML += "" + prop + "; // " + typeof object[prop] + "<br/>"; } </script> </body> </html> 

This displays all the properties of the object, including the functions available to this object, for example:

 ... insertAdjacentHTML; // function insertAdjacentText; // function insertAdjacentElement; // function getAttribute; // function setAttribute; // function removeAttribute; // function getAttributeNode; // function ... 

However, this will not work in IE9, all you get is the string / number / object properties and never has any function properties.

My question is, at runtime, can I find out what function names are exported by an object in IE9?

Thank you very much in advance.

UPDATE: adding doctype allows you to work as expected.

 <!DOCTYPE html> <body> <script> var object = document.createElement( "select" ); for( var prop in object ) { document.body.innerHTML += "" + prop + "; // " + typeof object[prop] + "<br/>"; } </script> </body> </html> 
+4
source share
2 answers

This code looks good to me and works in IE9 here.

http://jsbin.com/ivukus/edit#preview

+4
source

This works fine in IE if you specify DOCTYPE . Without DOCTYPE IE will display Quirks mode , which is essentially the behavior of IE 5.5, which will greatly affect IE Javascript support.

 <!doctype html> <html> <body> <script> var object = document.createElement( "select" ); for( var prop in object ) { document.body.innerHTML += "" + prop + "; // " + typeof object[prop] + "<br/>"; } </script> </body> </html> 

Result:

 form; // object length; // number multiple; // boolean name; // string options; // object selectedIndex; // number size; // number type; // string value; // string dataFld; // string dataFormatAs; // string dataSrc; // string add; // function item; // function namedItem; // function remove; // function . . . 
+2
source

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


All Articles