当前位置:网站首页>备忘一下es6的export/import和类继承的用法
备忘一下es6的export/import和类继承的用法
2022-06-30 02:48:00 【OK_boom】
备忘一下,不知道有没有理解错
export default 这个默认导出, import时直接导入名字即可,不要给名字加{}
export 后面带具体名字的(比如函数名,对象名), import时要 import 加上大括号{}
es6的类也有继承extends语法糖, 调用父类方法用super.xxx(),调用父类构建用super()
下面是例子, a.js是父类里面的代码:
class ParentClass{
sayHello(){
console.log("parent hello")
}
}
class ParentClass2 extends ParentClass{
sayHello(){
console.log("parent2 hello")
super.sayHello() //调用父类的方法
}
}
export default{
ParentClass2,
name: 'ExpParentClass'
}
export const ParentClass3={
sayHello(){
console.log("ParentClass3 Const hello")
}
}
b.js 引用a.js:
import {
ParentClass3} from './a.js'
import ExpParentClass from './a.js'
class Son extends ExpParentClass.ParentClass2{
sayHello(){
console.log("-------------------")
super.sayHello()
console.log("Son hello")
console.log("-------------------")
}
}
let p1=new ExpParentClass.ParentClass2()
p1.sayHello()
let son=new Son()
son.sayHello()
ParentClass3.sayHello()
这个目录应该有一个名为package.json, 通过npm init -y命令行生成, type要设置为module
{
"name": "study1",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
边栏推荐
- How to switch ipykernel to a different CONDA virtual environment in jupyterlab?
- Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)
- oracle怎么设置密码复杂度及超时退出的功能
- 重磅来袭--UE5的开源数字孪生解决方案
- Five cheapest wildcard SSL certificate brands
- Several key points recorded after reviewing redis design and Implementation
- CMake教程系列-02-使用cmake代码生成二进制
- 打造创客教育中精湛技艺
- Unity TimeLine 数据绑定
- Time complexity analysis
猜你喜欢
uniapp 地址转换经纬度
Matlab code running tutorial (how to run the downloaded code)
打造創客教育中精湛技藝
Cmake tutorial series -02- generating binaries using cmake code
A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022
FDA ESG规定:必须使用数字证书保证通信安全
Heavy attack -- ue5's open source digital twin solution
Raki's notes on reading paper: neighborhood matching network for entity alignment
How to use redis to realize the like function
FDA ESG regulation: digital certificate must be used to ensure communication security
随机推荐
unity的text首列有标点符号咋办
重看《Redis设计与实现》后记录几个要点
三层交换机和二层交换机区别是什么
Time complexity analysis
What is the difference between a layer 3 switch and a layer 2 switch
What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
(graph theory) connected component (template) + strongly connected component (template)
JMeter obtains cookies across thread groups or JMeter thread groups share cookies
Digicert、Sectigo、Globalsign代码签名证书的区别
Ffmpeg source code
Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share
Distributed file storage system fastdfs hands on how to do it
多卡服务器使用
2. < tag dynamic programming and 0-1 knapsack problem > lt.416 Split equal sum subset + lt.1049 Weight of the last stone II
What is certificate transparency CT? How to query CT logs certificate logs?
Precautions for purchasing wildcard SSL certificate
打造創客教育中精湛技藝
Xunwei enzhipu ITop - imx6 Development Platform
HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化
[dry goods sharing] the latest WHQL logo certification application process