类和继承

一、类的声明和实例化

1.类的声明

//声明
var
cat=function(){ this.name='aha'; }; console.log(cat); //Es6中的声明
class cat1{ constructor() {
this.name='cat2'; } } console.log(cat1);

输出:

 

 2.类的实例化

var cat2=new cat("black",4)

二、继承

构造函数,原型链继承:

 

posted @ 2021-10-02 09:35  陌菡  阅读(60)  评论(0)    收藏  举报