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

扫码支付做进商城网站热点新闻事件

扫码支付做进商城网站,热点新闻事件,金融网站建设运营方案,维护网站建设空间出租一、主要区别 ES5 的继承实质上是先创建子类的实例对象, 然后再将父类的方法添加 到 this 上(Parent.apply(this)) . ES6 的继承机制完全不同, 实质上是先创建父类的实例对象 this(所以必 须先调用父类的 super()方法…

一、主要区别

  1. ES5 的继承实质上是先创建子类的实例对象, 然后再将父类的方法添加
    到 this 上(Parent.apply(this)) .

  2. ES6 的继承机制完全不同, 实质上是先创建父类的实例对象 this(所以必
    须先调用父类的 super()方法) , 然后再用子类的构造函数修改 this。

  3. ES5 的继承时通过原型或构造函数机制来实现。

  4. ES6 通过 class 关键字定义类, 里面有构造方法, 类之间通过 extends 关
    键字实现继承。

  5. 子类必须在 constructor 方法中调用 super 方法, 否则新建实例报错。 因
    为子类没有自己的 this 对象, 而是继承了父类的 this 对象, 然后对其进行加工。
    如果不调用 super 方法, 子类得不到 this 对象。

  6. 注意 super 关键字指代父类的实例, 即父类的 this 对象。

  7. 注意: 在子类构造函数中, 调用 super 后, 才可使用 this 关键字, 否则
    报错。

function 声明会提升, 但不会初始化赋值。 Foo 进入暂时性死区, 类似于 let、
const 声明变量。

const bar = new Bar();  
// it's ok  
function Bar() {  this.bar = 42;  
}
const foo = new Foo();  
// ReferenceError: Foo is not defined
class Foo {  constructor() {  this.foo = 42;  }  
}  

二、class 声明内部会启用严格模式。

// 引用一个未声明的变量 function Bar() {  
baz = 42;  
// it's ok}const bar = new Bar();  
class Foo {  constructor() {  fol = 42;  // ReferenceError: fol is not defined  }  
}const foo = new Foo();  

三、class 的所有方法(包括静态方法和实例方法) 都是不可枚举的。

// 引用一个未声明的变量 
function Bar() {  this.bar = 42;
}
Bar.answer = function() { return 42;  
};  
Bar.prototype.print = function() {  console.log(this.bar);  
};  
const barKeys = Object.keys(Bar);  
// ['answer']
const barProtoKeys = Object.keys(Bar.prototype);  
// ['print']class Foo {  constructor() {  this.foo = 42;  } static answer() {  return 42;  } print() {  console.log(this.foo);  }
}
const fooKeys = Object.keys(Foo);  
// []
const fooProtoKeys = Object.keys(Foo.prototype);  
// []  

四、class 的所有方法( 包括静态方法和实例方法) 都没有原型对象 prototype, 所以也没有 constructor, 不能使用 new 来调用。

function Bar() {  this.bar = 42;  
}
Bar.prototype.print = function() {  console.log(this.bar);  
};  
const bar = new Bar();  
const barPrint = new bar.print();  // it's ok
class Foo {  constructor() {  this.foo = 42;  } print() {  console.log(this.foo);  }
}
const foo = new Foo();  
const fooPrint = new foo.print();  
// TypeError: foo.print is not a constructor  

必须使用 new 调用 class。

function Bar() {  this.bar = 42;  
}
// it's ok
const bar = Bar();  class Foo {  constructor() {  this.foo = 42;  }
}
const foo = Foo();  
// TypeError: Class constructor Foo cannot be invoked without 'new'  

五、class 内部无法重写类名。

function Bar() {  Bar = 'Baz';  // it's ok this.bar = 42;  
}
const bar = new Bar();  
// Bar: 'Baz'  
// bar: Bar {bar: 42} class Foo {  constructor() {  this.foo = 42;  Foo = 'Fol';  // TypeError: Assignment to constant variable  }
}
const foo = new Foo();  
Foo = 'Fol';  
// it's ok
http://www.mmbaike.com/news/59719.html

相关文章:

  • 正常做一个网站多少钱公司想建个网站怎么弄
  • 以蓝色为主色调的网站2345网址导航浏览器下载
  • 最新网站制作网络优化工程师主要做什么
  • 天气网站建设外链推广论坛
  • 给企业做网站推广好么网络营销服务外包
  • 企业为什么要做网站投放广告怎么投放
  • 网站建设之织梦模板市场营销公司有哪些
  • 什么值得买 网站开发百度灰色关键词排名技术
  • 凤楼网站怎么做的百度关键词排行榜
  • 视频网站怎样做seo关键词排名优化推荐
  • 可以做微信推送的网站外链发布软件
  • 中国公路建设招标网站吉林百度查关键词排名
  • 房地产网站制作公司海外免费网站推广
  • 做外贸有哪些免费的网站seo与sem的区别和联系
  • 天迈装饰网站建设项目网络营销的优势与不足
  • 长春网络推广公司小技巧seo外链发布平台有哪些
  • 如何部置网站到iis北京seo顾问服务
  • 河南安阳市地图seo关键词排名优化如何
  • 书画网站建设方案策划网络app推广是什么工作
  • 青岛网站开发如何做推广宣传
  • 用xml可不可以做网站seo培训学校
  • wap网站搭建百度科技有限公司
  • 太原网站seo服务网络营销的特点有
  • 如何做网站推广优化交换友情链接的方法
  • 疫情又要来了吗最新消息网络推广优化培训
  • 网站建设 cms 下载seo关键词查询工具
  • 禅城网站建设谷歌搜索引擎免费入口 香港
  • 百度贴吧引流推广方法关键词优化到首页怎么做到的
  • 政府网站wap门户建设方案晚上国网app
  • 别人网站html css js获取广州seo关键词优化是什么