JonoJames
JonoJames

Reputation: 1223

JavaScript Objects and constructor types

Recreate the same type of object

As per the Image Im trying to recreat that type of Object . Chrome Dev tools

Console.log(TabPanel) Gives me the return on the object but what I don't understand is how the function name

TabPanel : f TabPanel()

follows the f symbol in the log .

How can I recreate that type of object with a simple example I have tried to use constructors and prototypes . I'm not sure how they achieved this

the console log

Upvotes: 1

Views: 35

Answers (2)

Steve Vaughan
Steve Vaughan

Reputation: 2189

If you create your function with a name, then it will display like that in your console.

const TabPanel = function TabPanel() {};
console.log(TabPanel);

Will log as you show in your screenshot

If you wanted this as part of an object, you could do:

const TabPanel = {
    TabPanel: function TabPanel() { ... }
}

Which would log as an object, which when expanded would show you your named function.

Upvotes: 1

T.J. Crowder
T.J. Crowder

Reputation: 1075059

What devtools is showing you there is that the value of TabPanel property on the object you logged is a reference to a function called TabPanel (not an object created by TabPanel, the TabPanel function itself). Here's an example:

function Example() {
}
var o = {
  ex: Example
};
console.log(o);
Look in the real console.

That gives us:

enter image description here

Upvotes: 2

Related Questions