代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>继承</title>
</head>
<body>
<script>
// 之前的继承
// function Parent() {
// this.name = '你猜猜';
// this.age = 66;
// }
// Parent.prototype.showName=function(){
// return this.name;
// }
// function Child(){
// Parent.call(this)
// this.type='chis'
// }
// Child.prototype = Object.create(Parent.prototype)
// Child.prototype.constructor = Child;
// var c = new Child()
// console.log(c.showName())
// 之前的继承
// function Person(name,age){
// this.name=name;
// this.age=age;
// }
// Person.prototype.showName=function(){
// return this.name;
// }
// Person.prototype.showAge=function(){
// return this.age;
// }
// function Child(name,age){
// Person.apply(this,arguments)
// }
// Child.prototype = new Person()
// var c1 = new Person('abc',10)
// var c2 = new Person('ddd',20)
// console.log(c2.showName())
// 现在的继承
class Person{
constructor(name='defult',age=0){
this.name=name;
this.age=age
}
showName(){
return this.name;
}
showAge(){
return this.age;
}
}
class Child extends Person{
constructor(name,age,job='挖矿的'){
super(name,age);
this.job=job;
}
showJob(){
// return "您的工作是暂时的"
return this.job;
}
}
var p1 = new Child('hhh',101)
console.log(p1.showAge())
console.log(p1.showJob())
// function Parent() {
// this.name = '你猜猜我是谁';
// this.age = 66;
// }
// Parent.prototype.showName=function(){
// return this.name;
// }
// // function Child(){
// // Parent.call(this)
// // this.type='chis'
// // }
// class Child extends Parent{
// }
// var c = new Child()
// console.log(c.showName())
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。