深入理解ES6之《ES6中较小的改动》

发布时间:2019-08-10 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了深入理解ES6之《ES6中较小的改动》脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

识别整数

console.LOG(Number.isInteger(25))//true
console.log(Number.isInteger(25.0))//true
console.log(Number.isInteger(25.1))//false

安全整数

IEEE 754只能准确的表示-2的53次方到2的53次方的整数

let inside = Number.MAX_SAFE_INTEGER,
  outside = Number.MAX_SAFE_INTEGER + 1
  //Number.MIN_SAFE_INTEGER表示整数范围的下限
console.log(Number.isInteger(inside))//true
console.log(Number.isSafeinteger(inside))//true

console.log(Number.isInteger(outside))//true
console.log(Number.isSafeInteger(outside))//false

Unicode标识符

可以将Unicode转义序列用作标识符

let u0061 = 'abc'
console.log(u0061)//abc
console.log(a)//abc

可以使用Unicode码位转义序列来作为标识符

let u{61} = 'abc'
console.log(u{61})//abc
console.log(a)//abc

正式化__PRoto__属性

  1. 只能在对象字面量中指定一次__proto__,如果指定两个__prpto__属性则会抛出错误,这是唯一具有该限制的对象字面量改改
  2. 可计算形式的["__proto__"]的行为类似于普通属性,不会设置或返回当前对象的原型。与对象字面量属性相关的所有规则均适用于此形式,应用不可计算的形式则会抛出异常
    使用__proto__和使用Object.getPrototyPEOf或Object.setPrototypeOf方法的区别在于__proto__可以直接设置对象字面量的原型
let person = {
  getGreeting() {
    return 'hello'
  }
}
let dog = {
  getGreeting() {
    return 'woof'
  }
}
let friend = {
  __proto__: person
}
console.log(friend.getGreeting())//hello
console.log(Object.getPrototypeOf(friend) === person)//true
console.log(friend.__proto__ === person)//true
friend.__proto__ = dog
console.log(friend.getGreeting())//woof
console.log(Object.getPrototypeOf(friend) === dog)//true
console.log(friend.__proto__ === dog)//true

没有通过调用Object.create方法来创建friend对象,而是创建一个标准对象字面量,并将一个值赋给__proto__属性,换句话说,当使用Object.create方法创建对象时,必须为所有其它对象属性指定完整的属性描述符

脚本宝典总结

以上是脚本宝典为你收集整理的深入理解ES6之《ES6中较小的改动》全部内容,希望文章能够帮你解决深入理解ES6之《ES6中较小的改动》所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。