File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
packages/vrender-animate/src/executor Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11import { isFunction } from '@visactor/vutils' ;
22
3+ /**
4+ * 获取自定义类型
5+ * @param custom 自定义动画对象
6+ * @returns 0: 不是函数/类, 1: 是类, 2: 是函数
7+ */
38export function getCustomType ( custom : any ) : number {
4- return custom && isFunction ( custom ) ? ( / ^ c l a s s \s / . test ( Function . prototype . toString . call ( custom ) ) ? 1 : 2 ) : 0 ;
9+ if ( ! custom || ! isFunction ( custom ) ) {
10+ return 0 ;
11+ }
12+ // 正则表达式检查是最快的,优先使用
13+ const functionStr = Function . prototype . toString . call ( custom ) ;
14+ if ( / ^ c l a s s \s / . test ( functionStr ) ) {
15+ return 1 ;
16+ }
17+ // 检查箭头函数(没有prototype)
18+ if ( ! custom . prototype ) {
19+ return 2 ;
20+ }
21+ // 检查构造函数是否是它自己(ES5类)
22+ if ( custom . prototype . constructor === custom ) {
23+ // 检查prototype是否可写,类的prototype是不可写的
24+ const descriptor = Object . getOwnPropertyDescriptor ( custom , 'prototype' ) ;
25+ if ( descriptor && ! descriptor . writable ) {
26+ return 1 ;
27+ }
28+ }
29+ return 2 ;
530}
You can’t perform that action at this time.
0 commit comments