1、typescript
class Adaptee {oldMethods() {console.log('原有方法')}}interface Target {oldMethods: () => void;newMethods: () => void;}class Adapter extends Adaptee implements Target {newMethods() {console.log(`新增方法`)}}const adapter = new Adapter()adapter.oldMethods()adapter.newMethods()
2、javascript
function oldMethods() {console.log('原有方法')}function newMethods() {console.log(`新增方法`)}const _export = {newMethods,oldMethods}// 就好比如前端的 es6 moduleexport {newMethods,oldMethods}
总结
在前端这一块,适配器模式其实只要体现到核心思想,那代码可多种多样。
