当前位置:网站首页>ES6 combines multiple class methods
ES6 combines multiple class methods
2022-07-24 00:22:00 【Haoxing】
Preface :
es6 Newly added class Method , Now I want to merge many of them , Finally, a new method is generated .
Ideas :
We build new 3 File , Respectively index.js, login.js ,main.js
login.js and main.js Are the two class function , Merge them into index.js in
Implementation method :
1、 Object to merge
let login = {}
let main= {}
// Merge js
const apiObj = {
...login,
...main
}2、class Method inheritance
class Request {
constructor(){
}
}
// Create a new class Method , And then inherit request The object in it
class indexModel extends Request {
}3、class Method dynamic increase js Method
class indexModel{}
let apiObj = {
aaa(){},
bbb(){}
}
Object.assign(indexModel.prototype, apiObj)Specific source code :
request.js
export class Request {
constructor(){
}
_request()
}login.js
const login = {
// Sign in - Get users session_key
loginFun(data) {
return this.request({ url: '/wx/wxOpenid', data: data, method: 'POST' })
},
}
export default loginmain.js
const main = {
// Get the sign in information of the current user
getSignData(data) {
return this.request({ url: '/employee', data: data, method: 'GET' })
}
}
export default main
index.js
// To introduce the relevant js file
import { Request } from '../utils/request.js'
import login from './login'
import main from './main'
// Merge js
const apiObj = {
...login,
...main
}
// Create a new class Method , And then inherit request The object in it
class indexModel extends Request {
}
// Merge the good js, New for us class Method indexModel assignment
Object.assign(indexModel.prototype, apiObj)
// Send out
const http = new indexModel();
export default http边栏推荐
- Gbase 8C session information function (6)
- [wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
- docker搭建sonarqube,mysql5.7环境
- 如何提升数据质量
- Blog expression Encyclopedia
- GBase 8c 会话信息函数(五)
- It basic English
- 蓝绿部署、金丝雀发布、A/B测试是什么
- Gbase 8C access authority query function (V)
- What are blue-green deployment, Canary release and a/b test
猜你喜欢

Beifeng communication appeared in China (Xiamen) emergency exhibition | intelligent communication means are strong and eye-catching!

The name in Qiankun subapplication package.json becomes the default path

Take stock of 10 new layer1 to prepare for the next bull market

【译】Go RPC 入门:Hello World

PHP implements stripe subscription

Delete all data of specified query criteria in Oracle

加密技术应用

数仓数据指标和标签体系区别

PayPal subscription process and API request

Multi data source configuration of mongodb
随机推荐
Sed in-depth understanding and use
IT基础英语
Pytest interface automated test framework | pytest generates simple test reports
数仓数据指标和标签体系区别
Distributed cap principle
Gbase 8C binary string operator
数据模型设计方法概述
Nacos
A lot of happiness in learning
vulnhub wpwn: 1
Gbase 8C session information function (4)
Automatic escape processing in JMeter
Redis持久化机制RDB、AOF
GBase 8c 位串操作符(一)
Customize an object
Redis主从同步机制
Gbase 8C bit string operator (I)
高数_第2章多元函数微分学__偏导数的几何应用_空间曲线的切线与法平面
Mysql database foundation
As a programmer, is there anything you want to say to the newcomer?