请参考以下示例:index.etsimport { MethodListUtil } from './MethodListUtil'; @Entry @Component struct WebComponent { instance:MethodListUtil = new MethodListUtil() build() { Column() { Button('getMethodList') .onClick(() => { const methodList = MethodListUtil.getMethods(MethodListUtil) as string[] console.log('methodList====='+JSON.stringify(methodList)) }) } } }MethodListUtil.etsexport class MethodListUtil{ constructor() { } webTest(): string { console.log('Web test'); return "Web test"; } webString(): void { console.log('Web test toString'); } static getMethods(classInstance: ESObject): string[] { return Object.getOwnPropertyNames(classInstance.prototype).filter(name => typeof classInstance.prototype[name] === 'function' && name !== 'constructor'); } }
请参考以下示例:
index.ets
MethodListUtil.ets