提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
557 B

  1. import { getType } from './getType.js';
  2. import { isType } from './isType.js';
  3. export function isInstanceOf(value, classOrClassName) {
  4. if (typeof classOrClassName === 'function') {
  5. for (let p = value; p; p = Object.getPrototypeOf(p)) {
  6. if (isType(p, classOrClassName)) {
  7. return true;
  8. }
  9. }
  10. }
  11. else {
  12. for (let p = value; p; p = Object.getPrototypeOf(p)) {
  13. if (getType(p) === classOrClassName) {
  14. return true;
  15. }
  16. }
  17. }
  18. return false;
  19. }