function Person(name, age) {
this.age = age
this.name = name
}
Person.a = "a"
Person.prototype.say = function () {
console.log("Hello World");
}
function Student(name, age, score) {
// 继承
Person.call(this, name, age)
this.score = score
this.study = function () {
console.log("study");
}
}
Student.prototype = new Person()
Student.prototype.constructor = Student
Student.prototype.run = function () {
console.log("run");
}
// 静态属性,一般不需要吧?
for(let key in Person){
Student[key] = Person[key]
}
var stu = new Student("zs", 21, 18)
console.log(stu.name);
console.log(stu.score);
stu.study()
stu.say()
stu.run()
console.log(Student.a);
console.log(Person);
console.log(Student);
js 继承原理【终极】
最新推荐文章于 2022-07-15 15:39:49 发布