instanceOfString method

bool instanceOfString(
  1. String constructorName
)

Whether this JSAny? is an instanceof the constructor that is defined by constructorName, which is looked up in the globalContext.

If constructorName contains '.'s, the name is split into several parts in order to get the constructor. For example, library1.JSClass would involve fetching library1 off of the globalContext, and then fetching JSClass off of library1 to get the constructor.

If constructorName is empty or any of the parts or the constructor don't exist, returns false.

Implementation

bool instanceOfString(String constructorName) {
  if (constructorName.isEmpty) return false;
  final parts = constructorName.split('.');
  JSObject? constructor = globalContext;
  for (final part in parts) {
    constructor = constructor?[part] as JSObject?;
    if (constructor == null) return false;
  }
  return instanceof(constructor as JSFunction);
}