码迷,mamicode.com
首页 > 其他好文 > 详细

好玩的对象存储

时间:2021-06-18 19:56:24      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:start   lan   function   pre   为什么   test   var   排序   loading   

排序属性与常规属性

  1. 数字属性属于排序属性
  2. 其他的属于常规属性

function Foo() {
    this[100] = ‘test-100‘
    this[1] = ‘test-1‘
    this["B"] = ‘bar-B‘
    this[50] = ‘test-50‘
    this[9] =  ‘test-9‘
    this[8] = ‘test-8‘
    this[3] = ‘test-3‘
    this[5] = ‘test-5‘
    this["A"] = ‘bar-A‘
    this["C"] = ‘bar-C‘
}
var bar = new Foo()


for(key in bar){
    console.log(`index:${key}  value:${bar[key]}`)
}

看看v8堆内存

  1. 排序属性都被存在了elements对象下
  2. 常规属性不超过10个存在对象内称对象内存储,线性存储称为快属性

技术图片

  1. 超过10个常规属性后,另外10个常规属性都被放在了properties对象下

技术图片

  1. 属性很多时,properites不再是线性存储,而是以非线性的字典存储,这个时候就是慢属性
    技术图片

为什么建议少用delete属性删除对象

  1. 没有使用delete删除对象的属性前还是对象内属性
    技术图片

  2. 删除属性之后变成了,字典存储的慢属性
    技术图片

好玩的对象存储

标签:start   lan   function   pre   为什么   test   var   排序   loading   

原文地址:https://www.cnblogs.com/pluslius/p/14899033.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!