当前位置:网站首页>备忘一下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"
}
边栏推荐
- Mysql表数据比较大情况下怎么修改添加字段
- 【干货分享】最新WHQL徽标认证申请流程
- 【postgres】postgres 数据库迁移
- Network neuroscience——网络神经科学综述
- How to prevent duplicate submission under concurrent requests
- Unity timeline data binding
- Jupyter notebook displays a collection of K-line graphs
- CMake教程系列-02-使用cmake代码生成二进制
- Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
- 代码签名、驱动签名的常见问题解答
猜你喜欢

What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?

Linear algebra Chapter 3 summary of vector and vector space knowledge points (Jeff's self perception)

Five cheapest wildcard SSL certificate brands

Intel-Hex , Motorola S-Record 格式详细解析

Unity3D UGUI强制刷新Layout(布局)组件

Creating exquisite skills in maker Education

Unity timeline data binding

IBM websphere通道联通搭建和测试

公司电脑强制休眠的3种解决方案

【postgres】postgres 数据库迁移
随机推荐
Global and Chinese markets of liquid optical waveguides 2022-2028: Research Report on technology, participants, trends, market size and share
外汇交易平台哪个好?有监管的资金就安全吗?
What are the three paradigms of database
Cmake tutorial series-01-minimum configuration example
Jupyter notebook显示k线图集合
[on] [DSTG] dynamic spatiotemporalgraph revolutionary neural networks for traffic data impact
Merge sort
Cmake tutorial series -04- compiling related functions
论文回顾:Playful Palette: An Interactive Parametric Color Mixer for Artists
Network neuroscience——网络神经科学综述
CMake教程系列-05-选项及变量
How long is the general term of the bank's financial products?
Multi card server usage
2022护网行动在即,关于护网的那些事儿
Steam elements hidden in science and Technology Education
2022 the action of protecting the net is imminent. Things about protecting the net
FAQs for code signature and driver signature
[论]【DSTG】Dynamic SpatiotemporalGraph Convolutional Neural Networks for Traffic Data Imputation
【postgres】postgres 数据库迁移
What is digicert smart seal?