instanceOfString method - JSAnyUtilityExtension extension - dart:js_interop library (original) (raw)
bool instanceOfString(
- String constructorName )
Whether this [JSAny](../../dart-js%5Finterop/JSAny-extension-type.html)?
is an instanceof
the constructor that is defined by constructorName
, which is looked up in theglobalContext.
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 fetchingJSClass
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);
}