0

In Ruby's REPL (Read Evaluate Print Loop) irb, I can query object methods by calling Object.methods(), this returns an Array containing the public and private methods of the object in question (in the example below, I'm querying the String class) e.g.

>String.methods()
=> [:try_convert, :allocate, :new, :superclass, //truncated for brevity

I'm trying to learn Javascript and I'd like to know is there an equivalent function (this is not for coding, but for querying objects in the browser Console). I find this a very effective way to learn.

2

2 Answers 2

2

You can try following.

var Foo = {name: "jim", 
           age: 43, 
           announcer: function(){
                      return "I am foo function";
       }}; 
Object.keys(Foo); //returns array ["name", "age", "announcer"]

which returns array of object keys which you can iterate and determine if they are refering to function.

more detail here

Sign up to request clarification or add additional context in comments.

Comments

1

A good approximation of this functionality is

console.dir(<object>)

According to MDM console.dir:

Displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

Screen shot of console.dir

You can click on the output in the console to drill down into an objects functionaility, including methods inherirted from its prototype. It is supported in all modern desktop browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.