当前位置:网站首页>Note the use of export/import and class inheritance in ES6
Note the use of export/import and class inheritance in ES6
2022-06-30 02:53:00 【OK_ boom】
Just remember , I don't know if I have misunderstood
export default This default export , import You can import the name directly , Don't add... To the name {}
export Followed by a specific name ( Like the function name , Object name ), import When it comes to import Add braces {}
es6 Classes of also have inheritance extends Grammatical sugar , To call a parent class method super.xxx(), Call the parent class to build super()
Here is an example , a.js Is the code in the parent class :
class ParentClass{
sayHello(){
console.log("parent hello")
}
}
class ParentClass2 extends ParentClass{
sayHello(){
console.log("parent2 hello")
super.sayHello() // Calls a method of the parent class
}
}
export default{
ParentClass2,
name: 'ExpParentClass'
}
export const ParentClass3={
sayHello(){
console.log("ParentClass3 Const hello")
}
}
b.js quote 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()
This directory should have a name package.json, adopt npm init -y Command line generation , type To set up for 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"
}
边栏推荐
- Study diary: February 15, 2022
- c#控制台格式化代码
- 学术汇报(academic presentation)/PPT应该怎么做?
- Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share
- The Oracle main program is deleted, but the data is on another hard disk. Can I import the data again?
- Heavy attack -- ue5's open source digital twin solution
- Several key points recorded after reviewing redis design and Implementation
- Recursion frog jumping steps problem
- (graph theory) connected component (template) + strongly connected component (template)
- Raki's notes on reading paper: named entity recognition as dependency parsing
猜你喜欢
![[Postgres] Postgres database migration](/img/45/7074aa766640160a3b6f00b109cb2f.png)
[Postgres] Postgres database migration

Unity3d ugui force refresh of layout components

重磅来袭--UE5的开源数字孪生解决方案

并发请求下如何防重复提交

在php中字符串的概念是什么

Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.

Seven common errors of SSL certificate and their solutions

IBM websphere通道联通搭建和测试

What is the difference between a layer 3 switch and a layer 2 switch

Summary of knowledge points about eigenvalues and eigenvectors of matrices in Chapter 5 of Linear Algebra (Jeff's self perception)
随机推荐
Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
NLP text summary: data set introduction and preprocessing [New York Times annotated corpus]
学术汇报(academic presentation)/PPT应该怎么做?
Software testing skills, JMeter stress testing tutorial, transaction controller of logic controller (25)
Two methods of SSL certificate format conversion
2. < tag dynamic programming and 0-1 knapsack problem > lt.416 Split equal sum subset + lt.1049 Weight of the last stone II
2. 成功解决 BUG:Exception when publishing, ...[Failed to connect and initialize SSH connection...
Three solutions to forced hibernation of corporate computers
Jupyter notebook displays a collection of K-line graphs
最小栈详解
CMake教程系列-05-选项及变量
打造創客教育中精湛技藝
Call collections Sort() method, compare two person objects (by age ratio first, and by name ratio for the same age), and pass lambda expression as a parameter.
Intel hex, Motorola S-Record format detailed analysis
怎么使用Vant实现数据分页和下拉加载
What should academic presentation /ppt do?
What is an X.509 certificate? 10. 509 certificate working principle and application?
Lua Basics
CMake教程系列-03-依赖管理
Creating exquisite skills in maker Education