0
点赞
收藏
分享

微信扫一扫

C语言200行代码实现简易三子棋

艾晓雪 2023-05-14 阅读 49

es6 extends继承
原型式继承
构造函数继承
组合式继承
一 、
es6 extends继承
scala复制代码

class Child extends Parent{
constructor(){
super()
this.name=‘张三’
}
}

let child=new Child()
console.log(child.age,child.name) // 18 张三

二、原型式继承
javascript复制代码// 原型链继承
function Parent() {
this.age=50
}

function Child() {
this.name=‘张三’
}

Child.prototype=new Parent();
let child =new Child()
console.log(child.name,child.age) // 张三 50

三、构造函数继承
javascript复制代码// 构造函数
function Parent() {
this.age=50;
}

function Child() {
Parent.call(this)
this.name=‘张三’
}

let child=new Child()
console.log(child.age,child.name)

四、组合式继承
javascript复制代码// 构造函数
function Parent() {
this.age=50;
}

function Child() {
Parent.call(this)
this.name=‘张三’
}
Child.prototype=new Parent();
let child=new Child()
console.log(child.age,child.name) // 50 张三

举报

相关推荐

C语言实现简易三子棋

C语言三子棋

三子棋(C 语言)

【c语言】三子棋

三子棋C语言

三子棋(C语言)

三子棋C语言实现

0 条评论