1. 코드
const u = new UserController() as any;
const methodNames =
Object.getOwnPropertyNames(u.constructor)
.filter((v) => v !== 'name' && v !== 'length' && v !== 'prototype');
const methods = methodNames.map((v) => u.constructor[v]);
2. 함수화
function getMethodsInClass(classType: ClassType) {
const c = classType as any;
const methods =
Object.getOwnPropertyNames(c)
.filter((v) => v !== 'name' && v !== 'length' && v !== 'prototype')
.map((mn) => c[mn]);
// for(const method of methods) {
// // Can Do Something
// }
return methods;
}
2-1. 사용 예시
class TestClass
{
testMethod(){}
}
getMethodsInClass(TestClass);