If `console.dir(x, {showHidden: true, });` prints `TestController {}`, does that mean x empty?
I wrote some code that keeps erroring saying
click()
does not exist on my testController
object. To troubleshoot, I wrote this code:
Does TestController {}
mean the object has no functions, properties, getters/setters, methods (or whatever word categorizes all of these things), or do I need to pass in different options to see everything on it?45 Replies
console: dir() method - Web APIs | MDN
The method 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.
i dont see the 2nd parameter
I'm writing typescript, and this is the generated js file for my class:
so, no, there's no options or anything to send
are you running the code in the browser or in node?
node
but i'm using jsdom
that's why the code might appear otherwise
https://nodejs.org/api/util.html#utilinspectobject-options <-- why don't you try this instead?
well, I have in the past but console.dir supposedly calls it anyway
I guess I'll try it here too
yeah, but seems that that has a lot more options
maybe one of them will work for you
Could I be missing something else or does this confirm it's an empty object?
maxdepth as well set to null?
you mean
depth
?
same outputyes
then it's empty
if you're in vscode, you can press f12
and see if there's anything in it
you mean in debug mode or something?
no
oh no, nm
just the editor
put the prompt on the value, press f12 and it searches the definition
Yeah, it takes me to my file:
I don't understand how it's possible to
new TestController()
and get an empty object back
Am I making some obvious mistake?that's how objects work
you get an object when you call
new
an empty one?
no, it has 1 public method called
expect
why isn't
click
public?
also, why doesn't it say expect
is on the new TestController()
?I KNOW!
IT DOESN'T HAVE A CONSTRUCTOR
wait, that doesn't make sense
but if there is no defined constructor, doesn't it get a default, no-arg one?
yeah
that's why i said this
try to use
TestController.click
directly?
or pass TestController
to console.dir?the typescript compiler says click doesn't exist. I can for it to run anyway if you want.
hm...
So many questions, but is
[constructor]: [Circular *1],
normal?yes
it's a circular reference
it references
TestController
okay
the
length: 0
means it takes no arguments to create itI know how to read the rest of this output but I don't know what it tells me re:
new TestController()
returning an empty objectI KNOW WHAT IT MAY BE, and if it is that, it's dumb as hell
🙂
the object doesn't have anything
but the prototype does
and the prototype is part of the constructor
but what you have is no longer a constructor, but an instance to a class
i may be absolutely wrong
but it kinda makes sense
I would've assumed
inspect
would have shown me
I guess I'll create an empty constructor and see if that changes anythingdon't do that
just try to do
console.log(new TestController().click);
and see what it says[Function: click]
it works!
i was right
it didn't fetch the prototype 🤣
probably to avoid going down the prototype chain
I don't see that as an option to show in
inspect
either?i didn't see anything either
and it doesn't make sense either
it should show 1 prototype, i think
hm
well here's what my code does now:
yup, it doesn't go down the prototype chain
that's bizarre
but makes sense, as prototype chains can be extremely long
thank you for the help 🙂
you're welcome