書いてみました。
テストしてないのでちゃんと動作するか不安ですが。
js
1 class Test {
2 constructor(){
3 this.name = "taro";
4 }
5 say(){
6 console.log(this.name);
7 }
8 }
9
10 const test = new Test();
11
12 const getMethodNameOf = obj => {
13 const proto = Object.getPrototypeOf(obj);
14 if ( proto === null ) return [ ...Object.getOwnPropertyNames(obj).filter( p => obj[p] instanceof Function) ];
15 return [ ...Object.getOwnPropertyNames(obj).filter( p => obj[p] instanceof Function ), ...getMethodNameOf(proto)];
16 }
17
18 getMethodNameOf(test);
19
20/*
21constructor,say,toSource,toString,toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,__defineGetter__,__defineSetter__,__lookupGetter__,__lookupSetter__,constructor
22*/
23
24 getMethodNameOf(test).map(x=>test[x].toSource());
25/*
26class Test {
27 constructor(){
28 this.name = "taro";
29 }
30 say(){
31 console.log(this.name);
32 }
33 },say(){
34 console.log(this.name);
35 },function toSource() {
36 [native code]
37},function toString() {
38 [native code]
39},function toLocaleString() {
40 [native code]
41},function valueOf() {
42 [native code]
43},function hasOwnProperty() {
44 [native code]
45},function isPrototypeOf() {
46 [native code]
47},function propertyIsEnumerable() {
48 [native code]
49},function __defineGetter__() {
50 [native code]
51},function __defineSetter__() {
52 [native code]
53},function __lookupGetter__() {
54 [native code]
55},function __lookupSetter__() {
56 [native code]
57},class Test {
58 constructor(){
59 this.name = "taro";
60 }
61 say(){
62 console.log(this.name);
63 }
64 }
65*/
なお、.toSource()
メソッドは非標準なので、ご注意を。