Kevin Zhao wrote:
Thanks Rob.
Is there a way to get the collection of functions' names; like we get
the attributes for other objects; e.g. for a table cell with name of
"TD1", we can do
var objCell = document.all.TD1;
for (var i=0; i< objCell.attributes[0].length; i++)
{ alert(objCell.attributes[0].nodeName;}
Thank you.
Albion(052x)
There is no 'functions' collection. Collections are specified in the
DOM, functions are part of JavaScript. The difference between DOM and
JavaScript, or more correctly ECMAScript, is often not clearly understood.
When you declare a function like:
<script type="text/javascript">
function someFn() { };
</script>
Then a property with a name of 'someFn' is added to the global object
and its value is the content of the function. In a browser (HTML DOM)
environment, there is a window object that is, for all intents and
purposes, the global object. Or as section 10.1.5 of the ECMASpec says:
"...the window property of the global object is the global
object itself."
The window object has lots of properties, I'm not sure it is possible to
find all of the ones that were added by a script (though there might be).
Drop this into a page to see what's there:
<script type="text/javascript">
var prop,
wProps = [],
i=0;
for (prop in window){
wProps[wProps.length] = i++ + ' '
+ prop + ': ' + window[prop]
+ '<i>' + (typeof window[prop]) + '</i>'
;
}
document.write( wProps.join('<br>'));
</script>
There are also anonymous functions which may be harder to find.
--
Rob