可能我过于较真
function Student(name, age, sex) {
this.name = name
this.age = age
this.sex = sex
}
Student.sayHi = function () {
console.log('大家好 我是' + this.name)
}
Student.test = 'abc'
构造函数Student也是对象,为什么不能通过.sayHi直接添加方法呢?无论添加属性还是方法都添加不上
console.log('Student', Student);
Student ƒ Student(name, age, sex) {
this.name = name
this.age = age
this.sex = sex
}
学过 Java / C# / Golang 一类的 OOP 强类型语言吗?
这就是基本的静态方法和类方法的区别。
P.S. C# 3.0 后增加了可以在实例里访问静态方法的特性,但本质是个语法糖。