参考: https://github.com/miktam/sizeof
字节大小来自ECMAScript语言规范
Number:8字节(64位存储) String字符2字节布尔: 4字节const same={ } const test data={ a :111,b: 'ccc ',223360 foorean }const seen=new WeakSet () functionsizeofobj ) obj ) if ) obj===null ) return 0 let bytes=0 //目标key也占用内存I props.let I ) {无论{constkey=props[I]//value是否重复,keybytes=calculator(key ) if ) type of obj [ key ]==' object value为同一内存空间(只计算一次内存) if ) seen.has ) obj[key] ) ) continueseen.add ) obj[key] ) ) bytes=calcullululates (函数计算器(obj ) constobjtype=typeofobjswitch ) objtype ) case ' string 2 case ' boolean ' : return4case ' number ' : return8case ' object ' : if (array.isarray (obj ) ) /排列(1,2 )