Blogger Information
Blog 19
fans 1
comment 0
visits 12423
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
作用域、闭包,类与继承
▽空城旧梦
Original
645 people have browsed it

作用域

1.全局作用域
var a=100;
var 创建的变量是全局作用域
2.函数作用域
函数内部变量通过let创建
let a=100;属于私有变量
只能在函数内部访问
3.块作用域
{
创建在块中,的函数和变量只能在块中访问
var无效
}

闭包

通过闭包访问私有变量

  1. function demo()
  2. {
  3. let a=100;
  4. return function demo1(){
  5. return a;
  6. }
  7. }
  8. console.log(demo()())

类与继承

1.实例类

  1. class User1{
  2. constructor(name,email){
  3. this.name=name;
  4. this.email=email;
  5. }
  6. show(){
  7. name:this.name,email:this.email;
  8. }
  9. }

调用实用类需要new创建对象,来实现调用
2.静态类
1.静态变量

  1. static age=18;

2.静态方法

  1. static fetch(){
  2. 代码块
  3. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:写得太少了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post