javascript instanceof get type from string name
Posted
by dcp
on Stack Overflow
See other posts from Stack Overflow
or by dcp
Published on 2010-05-25T04:02:22Z
Indexed on
2010/05/25
4:11 UTC
Read the original article
Hit count: 228
JavaScript
|instanceof
Let's say I have this (assume the name variable is "receiver"):
if (!(receiver instanceof com.HTMLReceiver)) {
throw new com.IllegalArgumentException(
name + " is not an instance of com.HTMLReceiver.");
}
I'd like to factor this code out into a common method so I could call it like this:
Helper.checkInstance(receiver, "com.HTMLReceiver");
But I don't know of a way to convert the com.HTMLReceiver
from a string to its actual type so I can use instanceof
on it.
Is there a way?
© Stack Overflow or respective owner