Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I console.log functions alongside all their properties?

Tags:

javascript

I'm using the Google Chrome console. Frustratingly, the following code

var f = function () {};
f.a = 1;
console.log(f);

will only log

function () {}

Why does it not print the properties of f, such as f.a and f.prototype? How can I print them?

like image 778
Randomblue Avatar asked Dec 19 '11 23:12

Randomblue


People also ask

How do you see all properties of JavaScript function in console?

dir() The method console. dir() displays an interactive list of the properties of the specified JavaScript object.

Can you console log functions?

We can call any function inside a function, including console. log().

Is console log () added to execution stack?

It's a function call. It goes to the call stack.

Can I store console log in variable?

If you want to do this to an object that has been already logged (one time thing), chrome console offers a good solution. Hover over the printed object in the console, right click, then click on "Store as Global Variable". Chrome will assign it to a temporary var name for you which you can use in the console.


1 Answers

Try console.dir.

console.dir(f);
like image 78
Anurag Avatar answered Sep 29 '22 05:09

Anurag