From 54f60a5b88e370b8f51f36726132d078263e0e65 Mon Sep 17 00:00:00 2001 From: knoxHuang Date: Mon, 23 Sep 2024 13:48:07 +0800 Subject: [PATCH] Fix the issue with the getClassName error under ES6 --- cocos/core/utils/js-typed.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cocos/core/utils/js-typed.ts b/cocos/core/utils/js-typed.ts index b6ecea7e455..6b5668125ad 100644 --- a/cocos/core/utils/js-typed.ts +++ b/cocos/core/utils/js-typed.ts @@ -250,8 +250,7 @@ export function getClassName (objOrCtor: any): string { // for browsers which have name property in the constructor of the object, such as chrome if (objOrCtor.name) { ret = objOrCtor.name; - } - if (objOrCtor.toString) { + } else if (objOrCtor.toString) { let arr; const str = objOrCtor.toString(); if (str.charAt(0) === '[') { @@ -261,7 +260,7 @@ export function getClassName (objOrCtor: any): string { } else { // str is function objectClass () {} for IE Firefox // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec - arr = /function\s*(\w+)/.exec(str); + arr = /^function\s*(\w+)/.exec(str); } if (arr && arr.length === 2) { ret = arr[1];