-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method to determine the type of an object. #103
Comments
you don't need the RegExp, just |
Nice :) |
Unfortunately, both function decompilation and the
|
This blog post explains in greater detail how |
During my search for a function that is able to tell me the type of an object, I came up with the following idea:
Every object has a constructor (I am not sure about this)
obj.constructor
.You can convert the constructor to a string with
obj.constructor.toString()
. That returns something like"function Date() { [native code] }"
for aDate
.To get the string
"Date"
I use a regex, but perhaps a combination with indexOf and substr perform better.For performance reasons, i store the regex in a static variable. But again, there could be a different implementation.
Perhaps this idea is useful for you.
The text was updated successfully, but these errors were encountered: