★静态方法 定义的时候,方法名字前面加static 。使用的时候,直接通过类调用。静态方法可以被继承。
★直接通过类名定义的属性。属于静态属性,只能通过类调用,可以继承。
<script>
class Person{
constructor(){
}
static getId(){
console.log('getId')
}
}
Person.className='xxxx';
class Student extends Person{
}
var p=new Person();
// p.getId()实例对象不能使用静态方法
Person.getId()
Student.getId()
console.log(Person.className)
console.log(Student.className)
// console.log(p.className)
</script>