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

微信制作宣传网站有哪些内容在旅行社做网站运营

微信制作宣传网站有哪些内容,在旅行社做网站运营,类似5173的网站怎么做,重庆seo整站优化方案范文在 ES6 的 class 中,super 关键字的行为在 构造函数 和 非构造函数(普通方法) 中有显著区别,主要体现在以下方面: 1. 构造函数中的 super 行为规则 必须显式调用: 在子类的构造函数中,必须先调…

在 ES6 的 class 中,super 关键字的行为在 构造函数非构造函数(普通方法) 中有显著区别,主要体现在以下方面:


1. 构造函数中的 super

行为规则
  1. 必须显式调用
    在子类的构造函数中,必须先调用 super(),才能使用 this。否则会抛出错误:

    class Child extends Parent {constructor() {this.name = "Alice"; // ❌ 错误:Must call super constructor in derived classsuper();}
    }
    
  2. super 作为函数调用
    super() 的作用是调用父类的构造函数,并初始化子类实例的 this

    • 参数需传递给父类构造函数。
    • 相当于 Parent.prototype.constructor.call(this, ...args)
  3. 调用顺序
    super() 必须位于构造函数的最顶部(在访问 this 之前)。

示例
class Parent {constructor(name) {this.name = name;}
}class Child extends Parent {constructor(name, age) {super(name); // ✅ 必须先调用 super()this.age = age;}
}const child = new Child("Alice", 10);
console.log(child.name); // "Alice"
console.log(child.age);  // 10

2. 非构造函数中的 super(普通方法)

行为规则
  1. super 作为对象使用
    在普通方法中,super 指向 父类原型(Parent.prototype),用于调用父类方法。

    • super.method() 等价于 Parent.prototype.method.call(this)
  2. 可调用父类原型方法
    通过 super 可以访问父类原型上定义的方法,但无法直接访问父类实例属性。

  3. 无需强制调用顺序
    可以在方法内任意位置使用 super,无需在访问 this 之前调用。

示例
class Parent {sayHello() {console.log("Hello from Parent");}
}class Child extends Parent {sayHello() {super.sayHello(); // ✅ 调用父类方法console.log("Hello from Child");}
}const child = new Child();
child.sayHello(); 
// 输出:
// "Hello from Parent"
// "Hello from Child"

关键区别总结

特性构造函数中的 super非构造函数中的 super
调用形式必须作为函数调用(super()作为对象调用(super.method()
必要性必须显式调用,否则报错可选调用(根据需要)
作用初始化 this,继承父类实例属性调用父类原型方法
访问 this 的时机必须在 super() 调用之后可直接使用 this(无需前置条件)
静态方法中的行为无(静态方法无构造函数)super 指向父类(而非父类原型)

静态方法中的 super

在静态方法中,super 指向 父类本身,而非父类原型:

class Parent {static staticMethod() {console.log("Parent static method");}
}class Child extends Parent {static staticMethod() {super.staticMethod(); // 调用父类的静态方法console.log("Child static method");}
}Child.staticMethod(); 
// 输出:
// "Parent static method"
// "Child static method"

常见错误场景

1. 构造函数中遗漏 super
class Child extends Parent {constructor() { // ❌ 未调用 super(),抛出错误}
}
2. 在非构造函数中误用 super()
class Child extends Parent {method() {super(); // ❌ 语法错误:'super' keyword unexpected here}
}
3. 错误访问父类实例属性
class Parent {constructor() {this.value = 42;}
}class Child extends Parent {getValue() {return super.value; // ❌ 无法通过 super 访问父类实例属性(返回 undefined)}
}const child = new Child();
console.log(child.getValue()); // undefined

总结

  • 构造函数中的 super
    强制调用,用于初始化 this,确保父类实例属性正确继承。
  • 非构造函数中的 super
    用于调用父类原型方法,无需强制顺序,但需注意 super 的指向。
  • 静态方法中的 super
    指向父类本身,用于调用父类静态方法。

文章转载自:

http://h4FXffRu.qstjr.cn
http://3OrIoZf6.qstjr.cn
http://aOaRpLyp.qstjr.cn
http://GVKBiKPH.qstjr.cn
http://PDY6hUgs.qstjr.cn
http://idyr51uQ.qstjr.cn
http://F8t2zCSw.qstjr.cn
http://IaZsi9KX.qstjr.cn
http://irwWxIBg.qstjr.cn
http://i8YbbvcG.qstjr.cn
http://nB8slYGA.qstjr.cn
http://RVpekXIx.qstjr.cn
http://sDzOQHAJ.qstjr.cn
http://NeatYyOP.qstjr.cn
http://aayC13yK.qstjr.cn
http://pbNE3sr3.qstjr.cn
http://67IyH7PU.qstjr.cn
http://mKPYaXLr.qstjr.cn
http://MYPWcuKs.qstjr.cn
http://oBddz4xj.qstjr.cn
http://tIqywj11.qstjr.cn
http://NangQDaR.qstjr.cn
http://Ib4MI2AE.qstjr.cn
http://DM9TUOqq.qstjr.cn
http://i9YhmJvV.qstjr.cn
http://FT7c7p23.qstjr.cn
http://Zbus1Dn4.qstjr.cn
http://z2Bq1tE2.qstjr.cn
http://eAOHW1dC.qstjr.cn
http://H44x2Xeq.qstjr.cn
http://www.dtcms.com/wzjs/635631.html

相关文章:

  • 请问做网站需要什么软件邹城建网站
  • 班级优化大师官方网站公司建个网站要多少钱
  • 做游戏网站教程企业营业执照
  • 合肥网站的建设记事本做的网站链接怎么装饰
  • .net网站制作综合实训报告网站建设常识网站建设技术知识大全
  • 安徽省建设工程信息网站6装宽带需要多少钱
  • 北京公司网站制作价格开一家网络公司需要什么条件
  • 番禺做网站600元吴江网络推广
  • 全球外贸网站制作教程软文写作的基本要求
  • 萍乡网站开发iosapp开发工具
  • 长沙哪里做网站好知末网官网
  • 外贸网站能用阿里云吗新乡网站seo
  • 北京做网站最好的公司做网站交互
  • 快速搭建网站服务器重庆娱乐场所最新通知
  • 第一次做网站选多大空间网站开发介绍ppt
  • 中堂镇做网站网络推广营销公司
  • 万户网络网站顾问网站备案号不存在
  • 网站开发团队人员网站架构怎么做
  • 怎样设置网站西安专业的网站设计费用
  • 有域名有服务器怎么建站网络优化工程师有多累
  • 网站开发需要考什么证wordpress project
  • 帝国cms7.0网站搬家换域名换空间等安装教程品牌建设对企业的作用
  • 能够做物理题的网站网站开发专业培训学校
  • 康保网站制作网站建设 pdf教程
  • 做视频特技的网站百度服务中心人工24小时电话
  • 网站建设运营费用包括哪些软件开发用什么软件
  • 帝国cms 网站地址设置网页设计师培训课程多少钱
  • 常州建设银行新北分行网站新网seo关键词优化教程
  • 做网站需要知道什么软件东莞网站建设手袋加工
  • 织梦手机网站怎么修改wordpress 板块