当前位置:网站首页>ES6 - numerical extension and object extension
ES6 - numerical extension and object extension
2022-06-25 23:03:00 【Climbing procedural ape】
Number
(1)Number.EPSILON Indicates the minimum accuracy ,2.2204.......
console.log(0.1 + 0.2 === 0.3) // false
function equal(a, b) {
if (Math.abs(a - b) < Number.EPSILON) {
return true
}
return false
}
console.log(equal(0.1 + 0.2, 0.3)) // truenotes :
JavaScript There are no integers at all at the bottom of the language , All numbers are decimal (64 Bit floating point ), When calculating integers, you can implement, for example ,console.log(3/1) // 3, But the floating-point calculation is wrong console.log(0.3 / 0.1) //2.9999999999999996, When decimal precision is greater than 53 Or the data length is greater than 53 When a , The data may be incorrect .
(2)Number.isFinite() Determine whether a number is finite
console.log(Number.isFinite(0.3 / 0.1)) // true
console.log(Number.isFinite(0.3)) // true
console.log(Number.isFinite(100 / 0)) // false
console.log(Number.isFinite(Infinity)) // false(3)Number.isNaN Check whether a value is NaN
(4)Number.parseInt() Number.parseFloat() Will automatically intercept the number at the beginning of the given string
console.log(Number.parseInt('521hhh')) // 521
console.log(Number.parseFloat('0.521hhh')) // 0.521(5)Number.isInteger() Judge whether a number is an integer , Only values can be judged
console.log(Number.parseInt('521hhh')) // 521
console.log(Number.parseFloat('0.521hhh')) // 0.521(6)Math.trunc() Erase the decimal of a number
console.log(Math.trunc(5.21)) //5
(7)Math.sign() Judge whether a number is negative 、 Positive numbers 、0
object
(1)Object.is() Determine whether the two values are exactly equal
console.log(Object.is(120, 121)) // false
console.log(Object.is(120, 120)) // true
console.log(Object.is(NaN, NaN)) // true
console.log(NaN === NaN) // falseObject.is() Used to determine whether two values are the same , There are several cases where the two values are the same :
All are
undefinedAll are
nullAll are
trueorfalseAre two strings of the same length , And the characters corresponding to each serial number are the same
The same two objects ( Two objects have the same reference address )
Two identical numbers :
All are
+0All are
-0All are
NaNAre not
0It's notNaN, And it's worth the same
Object.is And == Operators get different results .== The values on both sides of the symbol are cast before comparison ( When they are of different types ).
Object.is And === The result of the operator is also different .- 0 === + 0 yes true, and Number.NaN === NaN yes false.
Determine if the two values are the same ——Object.is( ) - Let's have a look
(2) Object to merge -- The combination of configuration files is very useful
const CONFIG1 = {
host: '127.0.0.1',
port: '3306',
active:true
}
const CONFIG2 = {
host: '192.168.8.102',
port: '3309',
passeord: '123456',
username: 'hhh'
}
console.log(Object.assign(CONFIG1, CONFIG2))
(3) Set prototype object
What is a prototype
Every JavaScript object (null With the exception of ) Another object will be associated during creation , This object is what we call prototype , Every object inherits properties from the prototype . Ruan Yifeng javascript_JavaScript The core concept - Prototype 、 Prototype chain _weixin_39998541 The blog of -CSDN Blog
Fast grasp JS Interview questions 『 Prototypes and prototype chains 』_ Bili, Bili _bilibili
Implicit prototype -- By default, the object will have a __proto__, Point to the prototype of the class when the object is created ; The class itself has prototype, When you can't find a way , Will look up , That is, find in the prototype


Prototype chain -- Layer by layer inheritance , Prototypes form chains

teachet.hasOwnProperty() // The inspection method is own , Or the prototype
instanceof() When referencing a type , Can't use typeof See what the object is , Such as arrays and Object, Use instanceof It's viewable ,instanceof What you are looking at is that all on the prototype chain are true, If it doesn't exist in the prototype chain , All are false
Obeject.setPrototypeOf(school,cities) // Support all , That is, support objects , Also supports arrays , Theoretically, reference types can be used .

notes : It is not recommended to set the prototype later
边栏推荐
- Talk about adapter mode
- APP-新功能上线
- 荣耀推出积分商城,支持兑换各种荣耀产品
- Nacos 源码分析01 代码结构
- Yyds dry goods inventory JD 2, why is redis so fast?
- How do I project points on a 3D plane- How to project a point onto a plane in 3D?
- Why is BeanUtils not recommended?
- Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
- 实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)
- [eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
猜你喜欢

Data governance is easier said than done

2022-2028 global selective laser sintering service industry research and trend analysis report

数据治理,说起来容易,做起来难

Fastjson deserialization randomness failed

Civil Aviation Administration: by 2025, China will initially build a safe, intelligent, efficient and green aviation logistics system

实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)

Cvpr2022 tutorial | machine learning remote sensing processing: agriculture and food security, University of Maryland

Talk about adapter mode

2022-2028 global vacuum jacket system industry survey and trend analysis report

Use apiccloud AVM multi terminal component to quickly realize the search function in the app
随机推荐
2022-2028 global industrial TFT LCD industry survey and trend analysis report
Global and Chinese flame retardant ABS industry development trend and market demand analysis report 2022 ~ 2028
华为云SRE确定性运维专刊(第一期)
在线CRUDhasone关联查询报错Unabletouseinternalvariable:List
Multi modal data can also be Mae? Berkeley & Google proposed m3ae to conduct Mae on image and text data! The optimal masking rate can reach 75%, significantly higher than 15% of Bert
Simple and easy-to-use cache library gcache
数据治理,说起来容易,做起来难
记|一次exists关键字的学习记录
MATLAB Programming Notes
2022-2028 global iridium electrode industry research and trend analysis report
字符串变形(字符串大小写切换和变现)
Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
What do l and R of earphone mean?
民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
MySQL数据库索引
Unity technical manual - particle foundation main module attributes - upper
27 Chinese scholars including Yaoban and chendanqi from Tsinghua won the awards, and the list of winners of Sloan award in 2022 was issued
Ribbon core ⼼ source code analysis
2022-2028 global co extrusion production line industry research and trend analysis report
Wpewebkit debugging MSE playback