Where am I doing wrong?
I would wait "Class" as a result of this code but it doesn't:
This is from object function:
Tyepof doesnt work like that, it only returns built in types. You could try:
this.constructor.name==="Class";
It will check all the way up the prototype chain to see if this
or any prototype of this
is Class. So if OtherType.prototype=Object.create(Class);
then it'll be true for any OtherType instances. Does NOT work in < IE9
or
this instanceof Class
But that will not check the entire prototype chain.
Here is a list of return values typeof can return
Here is an answer about getting the type of a variable that has much more detail and shows many ways it can break.
Because JavaScript knows only the following types :
Undefined - "undefined"
Null - "object"
Boolean - "boolean"
Number - "number"
String - "string"
Host object (provided by the JS environment) - Implementation-dependent
Function object (implements [[Call]] in ECMA-262 terms) - "function"
E4X XML object - "xml"
E4X XMLList object - "xml"
Any other object - "object"
You can find more here
Read this thread to find how you can get the object name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With