Skip to content

2618. Check if Object Instance of Class

1
2
3
4
5
6
7
8
9
function checkIfInstanceOf(obj: any, classFunction: any): boolean {
  while (obj != null) {
    if (obj.constructor === classFunction) {
      return true;
    }
    obj = Object.getPrototypeOf(obj);
  }
  return false;
}