深入理解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方法创建对象时,必须为所有其它对象属性指定完整的属性描述符

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值