Noob question: is there a way to findout a class's methods without reading the source?

J

Jonas Smith

I'm new to javascript.

Is there a way to find out what methods a class has without having to
read the source of the class? especially the built-in classes?
 
R

RobG

I'm new to javascript.

Is there a way to find out what methods a class has without having to
read the source of the class?

Javascript doesn't have classes, however it does have objects that can
be used to imitate the behaviour of classes in other languages.

You can iterate over the enumerable properties of an object using
for..in and see which ones are functions, however you wont discover
the non-enumerable properties. Further, some browsers make it
difficult to tell if host object properties are functions or not, so
it is not a particularly good strategy.

especially the built-in classes?

The properties of built-in objects are not enumerable, nor is the
source code for them easily available. You're much better off to read
the ECMAScript Language specification:

<URL: http://www.mozilla.org/js/language/E262-3.pdf >
 
J

Jonas Smith

Javascript doesn't have classes, however it does have objects that can
be used to imitate the behaviour of classes in other languages.

You can iterate over the enumerable properties of an object using
for..in and see which ones are functions, however you wont discover
the non-enumerable properties. Further, some browsers make it
difficult to tell if host object properties are functions or not, so
it is not a particularly good strategy.



The properties of built-in objects are not enumerable, nor is the
source code for them easily available. You're much better off to read
the ECMAScript Language specification:

<URL: http://www.mozilla.org/js/language/E262-3.pdf >

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top