class Person {
constructor(name, age){
this.name=name;
this.age=age;
}
sayHello(){
console.log(this.name+ 'hello')
}
static haha() {
console.log('sss')
}
}
var p1=new Person('張三', 18)
p1.sayHello()
Person.haha()
複製代碼
function Person(name, age) {
this.name = name
this.age = age
}
Person.prototype.sayHello = function () {
console.log(this.name)
}
var p1 = new Person('張三', 18)
p1.sayHello()
複製代碼
class Person {
constructor(name, age){
this.name=name;
this.age=age;
}
sayHello(){
console.log(this.name+ 'hello')
}
static haha() {
console.log('sss')
}
}
class Student extends Person {
constructor(name, age, stuId) {
super(name, age)
this.stuId = stuId
console.log('子類')
}
study () {
console.log('我是子類')
}
}
const s1=new Student('張三', 18, 123)
s1.study()
s1.sayHello()
class Teacher extends Person {
constructor(name, age, salary) {
super(name, age)
this.salary= salary
}
teaching() {
console.log('teaching')
}
}
const t1=new Teacher('zzz',19, 100)
t1.sayHello()
複製代碼