当前位置:网站首页>ES6 related interview question 2
ES6 related interview question 2
2022-07-22 17:27:00 【Xiao Lu wants to brush the questions】
List of articles
super What is it? ?
: It's just a keyword Usage for super(…) perhaps super.xxx (…)
because super The grammatical definition of and this Different this Is defined as this This keyword will be replaced with a reference
super It is super(…) Will be replaced by a call Except in the constructor It's called directly in super Outside , You can also use super.xxx (…) To call a prototype method on the parent class , It's also a restricted grammar
Say the running results of the following program
(function() {
let a = this ? class b {
} : class c {
} ;
console.log(typeof a, typeof b , typeof c)
})()
The result is function undefined undefined
When defining function variables , Function names can only take effect in function bodies
How do you understand ES6 in Module Of ? What are the use scenarios ?
Introduce
modular ,(Module), It is a collection of program statements that can independently name and complete certain functions ( That is, the aggregation of program code and data structure ).
Two basic features : External and internal features
External feature refers to the interface between module and external environment ( That is, how other modules or programs call the module , Including input and output parameters 、 Global variables referenced ) And module functions
Internal characteristics refer to the characteristics of the internal environment of a module ( That is, the local data and program code of the module )
Why modularity is needed
Code abstraction
Code encapsulation
Code reuse
Dependency management
Without modularity , What will happen to our code ?
1) Variables and methods are not easy to maintain , Easy to pollute global scope
2) The way to load resources is through script Label from top to bottom .
3) The subjective logic of the dependent environment focuses on , More code will be more complex .
4) Large project resources are difficult to maintain , Especially when many people work together , The introduction of resources will make people run away
AMD
Asynchronous ModuleDefinition(AMD), Asynchronous module definition , Load the module asynchronously . All statements that depend on the module , Are defined in a callback function , Wait until the module is loaded , This callback function will run
The representative library is require.js
CommonJs
CommonJS It's a set Javascript The module specification , For the server
It has the following characteristics :
All code runs in the module scope , Does not contaminate the global scope
Modules are loaded synchronously , That is, only the loading is complete , To perform the following operations
The module is cached after its first execution , Reloading only returns cached results , If you want to execute again , The cache can be cleared
require The returned value is a copy of the output value , Changes within the module will not affect this value
ES6 At the level of language standards , Realized Module, Module function , It can completely replace CommonJS and AMD standard , Become a common module solution for browser and server
CommonJS and AMD modular , They can only be identified at runtime . such as ,CommonJS Modules are objects , You have to look for object properties when you type
Use
Module function is mainly composed of two commands :
export: It is used to specify the external interface of the module
import: It is used to input the functions provided by other modules
export
A module is a separate file , All variables within the file , External cannot get . If you want the external to be able to read a variable inside the module , Must use export Keyword output the variable
import
Use export After the command defines the external interface of the module , other JS The file can be passed import Command to load this module
Use scenarios
Now ,ES6 Modularity has gone deep into our daily project development , image vue、react Project construction project , Component development can be seen everywhere , It also relies on modular implementation
边栏推荐
- ABAQUS realizes modal calculation of two degree of freedom vibration system
- 分支语句和循环语句
- Win11开机只有鼠标显示怎么办?
- Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
- Getting started with VIM
- Cause du tampon / cache du serveur et libération du tampon / cache
- 浏览器页面的渲染流程
- Is it safe to open an account with the VIP link of Galaxy Securities? What is the lowest commission?
- Vivo official website app full model UI adaptation scheme
- 《PyTorch深度学习实践》-B站 刘二大人-day2
猜你喜欢
随机推荐
Abaqus实现二自由度振动系统模态计算
UART通信实验(查询方式)
es6相关面试题2
怎么使用js实现计算器和计时器功能
[pictures and texts] detailed tutorial of online one click reinstallation of win7 system
Win11遇到问题需要重启怎么办?
Domain Driven Design
flask框架添加异步任务处理模型任务
mysql约束之_主键约束PRIMIARY KEY
Castor realizes high-throughput analysis of large-scale cloud assembly through polygonica 3D engine, and hoops exchange helps it read CAD data files
【外部排序】快排思想完成外部排序
This article introduces you to the workflow of Redux - action/reducer/store
How to solve the problem of uncontrollable win11 flashing white screen?
"New capabilities" of rongyun Super Group
BigInteger: what does new BigInteger (tokenjason. Getbytes()). ToString (16) mean
What is numpy?
C语言分支结构和循环结构(1)
Principle and performance analysis of lepton lossless compression
Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
final、finally、finalize的区别