0

What's the correct way to discover what kind of thing an object is. I'm trying to debug a process which makes use of a lot of d3 object. I suspect that one object might not be the kind of thing that we expect it to be. I'd like to be able to log the name of the object. In python I could do:

foo.__class__.__name__

But what's the JavaScript equivalent? Given a mystery object I just want to know what kind of thing it is. In this example, I want to know that foo is actually a d3.map:

coffee> foo = d3.map()
{ _: {} }
coffee> foo.prototype
undefined
coffee> foo
{ _: {} }
coffee>

The method described in "How do I get the name of an object's type in JavaScript?" does not seem to work here because foo's prototype is undefined.

Community
  • 1
  • 1
Salim Fadhley
  • 6,975
  • 14
  • 46
  • 83
  • I don't think that works here - in my 2nd block of example code we can see that foo.prototype gives undefined. – Salim Fadhley Aug 26 '15 at 11:55
  • @SalimFadhley: That method does not use `.prototype` property? Of course your instances don't have `.prototype` properties, they are no functions. They do however have [prototypes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf) that they inherit from. – Bergi Aug 26 '15 at 12:18

0 Answers0