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

艾晓雪

关注

阅读 49

2023-05-14

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 张三

精彩评论(0)

0 0 举报