慕侠4357865
2018-08-24 16:10
在mobx5中Array.isArray(arr)的值为true,是怎么做到的呢?
https://github.com/mobxjs/mobx/blob/master/src/types/observablearray.ts#L506
export function isObservableArray(thing): thing is IObservableArray<any> { return isObject(thing) && isObservableArrayAdministration(thing[$mobx]) }
const isObservableArrayAdministration = createInstanceofPredicate( "ObservableArrayAdministration", ObservableArrayAdministration )
export function createInstanceofPredicate<T>( name: string, clazz: new (...args: any[]) => T ): (x: any) => x is T { const propName = "isMobX" + name clazz.prototype[propName] = true return function(x) { return isObject(x) && x[propName] === true } as any }
mobx入门基础教程
18816 学习 · 54 问题
相似问题