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

电子商务系统网站开发总结企业邮箱app下载

电子商务系统网站开发总结,企业邮箱app下载,广告设计与制作专业课程,怎么做可以把网站图片保存下来Question JavaScript实现继承的方式#xff1f; 包含原型链继承、构造函数继承、组合继承、原型式继承、寄生式继承、寄生组合式继承和ES6 类继承 JavaScript实现继承的方式 在JavaScript中#xff0c;实现继承的方式多种多样#xff0c;每种方式都有其优势和适用场景。以下… Question JavaScript实现继承的方式 包含原型链继承、构造函数继承、组合继承、原型式继承、寄生式继承、寄生组合式继承和ES6 类继承 JavaScript实现继承的方式 在JavaScript中实现继承的方式多种多样每种方式都有其优势和适用场景。以下是一些常见的继承方式 1. 原型链继承 原型链继承是通过将子类的原型设置为父类的实例来实现继承。这样子类就可以访问父类原型上的属性和方法。 function Parent() {  this.name  Parent;}function Child() {}Child.prototype  new Parent();const childInstance  new Child();console.log(childInstance.name); // 输出 Parent 优势 简单易懂。 缺点 引用类型的属性会被所有实例共享无法传递参数给父类构造函数。 2. 构造函数继承 构造函数继承通过在子类构造函数中调用父类构造函数来实现继承。 function Parent(name) {  this.name  name || Parent;}function Child(name) {  Parent.call(this, name);}const childInstance  new Child(Child);console.log(childInstance.name); // 输出 Child 优势 解决了原型链继承中引用类型属性共享的问题。 缺点 方法都在构造函数中定义无法实现函数复用。 3. 组合继承 组合继承结合了原型链继承和构造函数继承通过调用父类构造函数设置实例属性再通过将父类实例作为子类原型来实现。 function Parent(name) {  this.name  name || Parent;}function Child(name) {  Parent.call(this, name);}Child.prototype  new Parent();const childInstance  new Child(Child);console.log(childInstance.name); // 输出 Child 优势 同时继承实例属性和方法。 缺点 调用了两次父类构造函数存在一定的性能问题。 4. 原型式继承 原型式继承通过创建一个空对象然后将该对象作为参数传递给一个函数该函数的原型被赋值为这个对象从而实现继承。 function createObject(obj) {  function F() {}  F.prototype  obj;  return new F();}const parent  {  name: Parent};const child  createObject(parent);console.log(child.name); // 输出 Parent 优势 简单灵活。 缺点 属性共享问题引用类型属性会被所有实例共享。 5. 寄生式继承 寄生式继承在原型式继承的基础上增加了对父类构造函数的调用从而可以传递参数给父类构造函数。 function createObject(obj) {  const clone  Object.create(obj);  clone.sayHello  function() {    console.log(Hello!);  };  return clone;}const parent  {  name: Parent};const child  createObject(parent);console.log(child.name); // 输出 Parentchild.sayHello(); // 输出 Hello! 优势 可以在对象上添加新的方法。 缺点 仍然存在属性共享问题。 6. 寄生组合式继承 寄生组合式继承是为了解决组合继承中调用两次父类构造函数的性能问题通过使用 Object.create 创建父类原型的副本然后将该副本赋值给子类原型。 function inheritPrototype(child, parent) {  const prototype  Object.create(parent.prototype);  prototype.constructor  child;  child.prototype  prototype;}function Parent(name) {  this.name  name || Parent;}function Child(name) {  Parent.call(this, name);}inheritPrototype(Child, Parent);const childInstance  new Child(Child);console.log(childInstance.name); // 输出 Child 优势 解决了组合继承的性能问题同时保持了原型链继承的优点。 缺点 略显繁琐。 7. ES6 类继承 ES6 引入了 class 关键字使得面向对象编程更加直观。通过 extends 关键字可以实现类的继承。 class Parent {  constructor(name) {    this.name  name || Parent;  }}class Child extends Parent {  constructor(name) {    super(name);  }}const childInstance  new Child(Child);console.log(childInstance.name); // 输出 Child 优势 语法更加简洁易读易写。 缺点 底层仍然是基于原型链的继承。 100小程序源码关注公众号回复 5 获取不想看激励视频的可私信 本文由 mdnice 多平台发布
http://www.dnsts.com.cn/news/253384.html

相关文章:

  • 推荐企业手机网站建设邢台贴吧最新消息
  • 邳州市建设局网站代理平台盈利模式
  • 网站建设全视频教程下载word版免费个人简历模板
  • 杭州网站建设ttmwlwordpress 多的模板
  • 做网站价格差异很大新站网站推广公司
  • 数字币网站开发word网站超链接怎么做
  • wordpress 如何汉化网站排名优化学习
  • 河南省建设厅网站资质平移办法做电器的集团网站
  • 中文网站的英文西安建设公司网站
  • 中国的网站建设数据分析北京的制作网站的公司
  • 山西网站建设公司排名铜陵电子商务网站建设
  • 门户 网站 asp怎么做一个购物平台网站
  • 如何做公司网站空间网站的风格对比信息表
  • 外贸网站建设维护域名抢注网站
  • 怎样建设企业网站网站后台系统使用
  • 盘锦门户网站制作检测网站死链
  • 江苏建设局网站wordpress theme api
  • 企业网站的建设专业服务门店装修设计公司
  • 优购商城网站建设来宾网站建设
  • 济南设计公司招聘信息seo高清视频教程
  • 搜狗站长工具平台网站建设评估
  • 陕西煤业化工建设集团网站dw个人简历网页制作模板
  • 鼓楼做网站青岛代理记账有限公司
  • 怎么制作网站开发设计百度网盘在线登录入口
  • 济南做网站找大标中山网站建设文化方案
  • 做网站需要会什么条件如何安装wordpress模板
  • 用于做分析图 的地图网站茶山网站仿做
  • 制作免费网站的平台深圳市建设主管部门门户网站
  • 在网上做企业网站怎么做天元建设集团有限公司工程
  • 微网站功能介绍长春seo按天计费