Reputation: 116353
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?
Upvotes: 9
Views: 2616
Reputation: 57703
Because a function is not an object.
If you do:
var f = function () {};
var my_instance = new f(); // aha!
my_instance.a = 1;
console.log(my_instance);
You should get what you expect.
A function can be a class, but never an object. Use new
.
Upvotes: 0
Reputation: 237975
console.dir
lists all the defined properties of an object. I think this is probably what you're looking for.
How this appears in FF (Firebug)
How this appears in Chromium's console
I'm not sure if there's any Chrome documentation on this functionality, but there is Firebug documentation on the console
object.
Upvotes: 3