React01-面向对象开发

91 阅读1分钟

React01-面向对象开发

面向对象开发是一种开发模式。

面向对象、面向过程

对于目前我们市面上语言来说,java、python、js都是面向对象编程语言。c语言面向过程

js中编程、面向对象、函数式编程。

react开发过程中,面向对象开发模式、函数式的方式

类的定义

回顾es6的面向对象、es5面向对象

class Student{    //创建一个对象,首先会执行构造器。内存分配空间,初始化数据    constructor(name,age){    }}function User(){}//在堆空间里面开辟一个空间存放 Student对象。s存放在栈里const s = new Stdeunt()

类的属性

class Student{    // 定于属性    name;    age;    constructor(name,age){        this.name = name        //s2.name = name        this.age = age    }}const s2 = new Student()const s3 = new Student()s3.address = ”wuhouqu“

行为

class Student{     constructor(name,age){        this.name = name        this.age = age         this.show = function(){         }    }    play(){    }}new Student().show()

区别:写在构造器外面的行为默认会挂载到原型对象身上

静态属性和行为

面向对象里面,属性和行为分为两类

  1. 成员的属性和行为:new出来的这个对象直接使用,类内部定义
  2. 类的属性和行为:只有类才能使用的属性和行为。静态属性
class Student {    static address = "武侯区"    constructor(name, age) {        this.name = name        this.age = age    }    static random(){    }}Student.type = "会员"

类身上的属性不能被实例对象访问。只能被类访问

静态方法里面不能调用成员属性

知识点一:js中变量提升和函数提升,函数提升优先级更高。但是如果变量的值有覆盖,覆盖后的结果最终结果。

知识点二:一个变量没有任何修饰符,默认挂载全局对象身上。