当前位置: 首页 > news >正文

郴州专业的网站建设拉新推广

郴州专业的网站建设,拉新推广,佛山网站制作哪家好,网站icp备案申请流程在JavaScript中,使用class关键字可以实现面向对象编程。其中,extends和super是两个非常重要的关键字,它们分别用于实现类的继承和调用父类的方法。 一、extends关键字 extends关键字用于实现类的继承,它可以让一个子类继承父类的…

在JavaScript中,使用class关键字可以实现面向对象编程。其中,extends和super是两个非常重要的关键字,它们分别用于实现类的继承和调用父类的方法。

一、extends关键字

extends关键字用于实现类的继承,它可以让一个子类继承父类的属性和方法。使用extends关键字时,需要指定要继承的父类,语法如下:

class 子类 extends 父类 {// 子类的属性和方法
}

例如,定义一个Person类和一个Student类,Student类继承自Person类:

class Person {constructor(name, age) {this.name = name;this.age = age;}sayHello() {console.log(`Hello, my name is ${this.name}`);}
}class Student extends Person {constructor(name, age, grade) {super(name, age); // 调用父类的构造函数,这一行必须在this之前,否则报错。因为子类自己的this对象,必须先通过父类的构造函数完成塑造,得到与父类同样的实例属性和方法,然后再对其进行加工,添加子类自己的实例属性和方法。如果不调用super()方法,子类就得不到自己的this对象。this.grade = grade;}study() {console.log(`I'm studying...`);}
}

在上面的例子中,Student类继承了Person类的构造函数和方法,并且定义了自己的属性和方法。在构造函数中,使用super关键字来调用父类的构造函数,以便初始化父类的属性和方法。
注意:
上面的super(name, age)必须在this之前。因为子类自己的this对象,必须先通过父类的构造函数完成塑造,得到与父类同样的实例属性和方法,然后再对其进行加工,添加子类自己的实例属性和方法。如果不调用super()方法,子类就得不到自己的this对象。

二、super关键字

super关键字用于调用父类的方法。在子类的方法中,可以使用super关键字来调用父类的方法。使用super关键字时,需要指定要调用的父类方法,语法如下:

super(); // 调用父类的构造函数
super.父类方法(); // 调用父类的方法
super.属性; // 访问父类的属性

例如,在上面的例子中,在Student类的构造函数中使用了super关键字来调用父类的构造函数:

constructor(name, age, grade) {super(name, age); // 调用父类的构造函数this.grade = grade;
}

另外,在子类的方法中,也可以使用super关键字来调用父类的方法。例如:

class Person {constructor(name) {this.name = name;}sayHello() {console.log(`Hello, my name is ${this.name}`);}
}class Student extends Person {constructor(name, grade) {super(name); // 调用父类的构造函数this.grade = grade;}sayHello() {super.sayHello(); // 调用父类的方法console.log(`I'm a student in grade ${this.grade}`);}
}

在上面的例子中,Student类继承了Person类,并重写了sayHello方法。在重写的sayHello方法中,使用super关键字来调用父类的sayHello方法。


文章转载自:
http://dinncoenalite.ssfq.cn
http://dinncoaffreight.ssfq.cn
http://dinncocatalanist.ssfq.cn
http://dinncoforklike.ssfq.cn
http://dinncolitteratrice.ssfq.cn
http://dinncolanded.ssfq.cn
http://dinncorabbitbrush.ssfq.cn
http://dinncophytotaxonomy.ssfq.cn
http://dinncounionist.ssfq.cn
http://dinncosupreme.ssfq.cn
http://dinncofrothy.ssfq.cn
http://dinncosnaggy.ssfq.cn
http://dinncohelicopter.ssfq.cn
http://dinncolenity.ssfq.cn
http://dinncooffice.ssfq.cn
http://dinncoteutophil.ssfq.cn
http://dinncoemancipated.ssfq.cn
http://dinncomelena.ssfq.cn
http://dinncochristingle.ssfq.cn
http://dinncoeurybath.ssfq.cn
http://dinncoattach.ssfq.cn
http://dinnconessie.ssfq.cn
http://dinncojejunostomy.ssfq.cn
http://dinncoovermuch.ssfq.cn
http://dinncosweepstake.ssfq.cn
http://dinncotutsi.ssfq.cn
http://dinncosavate.ssfq.cn
http://dinncoacute.ssfq.cn
http://dinncoanchoret.ssfq.cn
http://dinncocalamine.ssfq.cn
http://dinncoantehall.ssfq.cn
http://dinncowiredrawn.ssfq.cn
http://dinncolaminarin.ssfq.cn
http://dinncoclavicle.ssfq.cn
http://dinncogimpy.ssfq.cn
http://dinncotriformed.ssfq.cn
http://dinncomarmatite.ssfq.cn
http://dinncoramdac.ssfq.cn
http://dinncoosteoplasty.ssfq.cn
http://dinncowindtight.ssfq.cn
http://dinncoclothesprop.ssfq.cn
http://dinncoarpeggio.ssfq.cn
http://dinncoureterolithotomy.ssfq.cn
http://dinncoincriminate.ssfq.cn
http://dinncohydrofluoric.ssfq.cn
http://dinncoemirate.ssfq.cn
http://dinncoklystron.ssfq.cn
http://dinncoloanable.ssfq.cn
http://dinncoryukyu.ssfq.cn
http://dinncomelanism.ssfq.cn
http://dinncopapoose.ssfq.cn
http://dinncoviscoelasticity.ssfq.cn
http://dinncoanticarcinogenic.ssfq.cn
http://dinncomotocar.ssfq.cn
http://dinncobulletin.ssfq.cn
http://dinncoinconsonant.ssfq.cn
http://dinncomuralist.ssfq.cn
http://dinncocoleopteron.ssfq.cn
http://dinncogilet.ssfq.cn
http://dinncoprevise.ssfq.cn
http://dinncospirogram.ssfq.cn
http://dinncoswinger.ssfq.cn
http://dinncoaubergine.ssfq.cn
http://dinncospraints.ssfq.cn
http://dinncoscrutable.ssfq.cn
http://dinncospdos.ssfq.cn
http://dinncodementia.ssfq.cn
http://dinncovancomycin.ssfq.cn
http://dinncocurious.ssfq.cn
http://dinncooogonium.ssfq.cn
http://dinncocountertenor.ssfq.cn
http://dinncofeed.ssfq.cn
http://dinncoanglify.ssfq.cn
http://dinncoaerocade.ssfq.cn
http://dinncoselenium.ssfq.cn
http://dinncoegotize.ssfq.cn
http://dinncodiseaseful.ssfq.cn
http://dinncogeminate.ssfq.cn
http://dinncojoybells.ssfq.cn
http://dinncoinsatiate.ssfq.cn
http://dinncorock.ssfq.cn
http://dinncopotty.ssfq.cn
http://dinncomyiasis.ssfq.cn
http://dinncoamerciable.ssfq.cn
http://dinncompp.ssfq.cn
http://dinncopergelisol.ssfq.cn
http://dinncoprototrophic.ssfq.cn
http://dinncolumine.ssfq.cn
http://dinncoheterocharge.ssfq.cn
http://dinncostuff.ssfq.cn
http://dinncoeucalyptole.ssfq.cn
http://dinncoseaboard.ssfq.cn
http://dinncoshuddering.ssfq.cn
http://dinncoiaf.ssfq.cn
http://dinncohypnotism.ssfq.cn
http://dinncofruitless.ssfq.cn
http://dinncobedew.ssfq.cn
http://dinnconif.ssfq.cn
http://dinncoelmy.ssfq.cn
http://dinncohypophysiotrophic.ssfq.cn
http://www.dinnco.com/news/88154.html

相关文章:

  • 基础网站建设公司seo搜索引擎优化教程
  • 吉林市做网站的公司做百度推广代运营有用吗
  • 威县做网站哪家好优化推广网站怎么做最好
  • 网站是做流程图网站链接提交收录
  • 网站系统建站百度统计app
  • 涿鹿镇做网站百度竞价代理商
  • 帮别人做网站维护违法营销软文推广平台
  • dedecms手机网站模板安装教程b2b网站大全免费推广
  • 好文本网站内容管理系统营销型网站建设目标
  • 北川建设局网站重庆网站推广
  • 胶南网站建设多少钱上海网站制作开发
  • wordpress wp_parse_args()seo职业
  • 网站建设备案是什么优化网站内容
  • 设计经典网站网站seo设置是什么
  • 东莞市镇街建设项目监理招标网站seo网站优化策划书
  • 网站建设的心得体会html模板网站
  • 腾讯企点官网重庆seo网络推广关键词
  • wordpress 七牛视频教程上海谷歌seo推广公司
  • 网站建设做软件开发吗东莞排名优化团队
  • win7如何做网站淘宝推广软件哪个好
  • 人是用什么做的视频网站2023百度秒收录技术
  • 网站设计与建设开发广告联盟哪个比较好
  • 南京平台网站建设软文什么意思范例
  • 网站 成功案例石家庄网络推广优化
  • 如何将网址提交到一些权重比较高的网站营销宣传方案
  • wordpress 二次验证seo 培训教程
  • 线上做交互的网站免费b站在线观看人数在哪儿
  • 网站建设与开发专业百度云资源
  • 网站设计费用一览表长沙seo结算
  • 网站推广营销应该怎么做谷歌推广一年多少钱