3 Star 6 Fork 1

tutu/ESC6

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
继承.html 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
tutu 提交于 2018-09-11 17:40 +08:00 . first ES6
<!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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/huangjuntu/ESC6.git
git@gitee.com:huangjuntu/ESC6.git
huangjuntu
ESC6
ESC6
master

搜索帮助