类组件

// 类组件
class Person {
  // constructor是类中的构造器
  // 每一个类中,都有一个构造器
  // 作用 每当new这个类的时候,必然会先优先执行 构造器中的代码
  constructor (name,age) {
    this.name =name
    this.age = age
  }
  sayHi () {
    console.log(this)
  }
}
let person = new Person('李李')
console.log(person)
person.sayHi()

  关键字:class、constructor 

function Fun(name,age) {
  this.name = name
  this.age = age
}
Fun.gender = '女' // 属于静态属性,并没有挂载到this上
const fun = new Fun ('哈哈',17)
console.log(fun.gender) // undefined

  

解决方案 :https://blog.csdn.net/lfcss/article/details/79627646

 

posted @ 2019-10-27 15:46  秋风渡明月  阅读(646)  评论(0编辑  收藏  举报