V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  USDT  ›  全部回复第 2 页 / 共 2 页
回复总数  21
1  2  
2023-08-01 21:25:44 +08:00
回复了 humbass 创建的主题 Node.js 如何获得 class 内部的方法?
用 Reflect

class App {
constructor() {
// 如何在这里获得 App 下面的所有方法?
const {ownKeys, getPrototypeOf} = Reflect;
console.log('methods:', ownKeys(getPrototypeOf(this)));
// 多了一个 constructor ,自行 filter 下
}
play() {}
unplay() {}
pause() {}
dosome() {}
dosome2() {}
}
new App() // output: [ 'constructor', 'play', 'unplay', 'pause', 'dosome', 'dosome2' ]
1  2  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5372 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 07:34 · PVG 15:34 · LAX 00:34 · JFK 03:34
Developed with CodeLauncher
♥ Do have faith in what you're doing.