Today, I will study the extension of object and Symbol in ES10 together with you. Although these two features are seldom used in the actual project, at least I am familiar with them first. When I see the big guy’s code, I will be proud to know that there is such a thing. We can also pay attention to my micro letter public number, snail full stack.
A, JSON superset
eval('var str="school"; function foo(){return str; } ')
console.log(foo()) // school
eval('var str="school"; \u2029 function foo(){return str; } ') // \u2028 line separator \u2029 paragraph separator
console.log(foo()) // school
Copy the code
Json.stringify () enhancements (previously range 0xDB00 to 0xDfff)
console.log(JSON.stringify('\uD83D\uDE0E')) // Emoji wearing sunglasses
console.log(JSON.stringify('\uD83D')) // "\ud83d" is used to output special characters
Copy the code
Third, Symbol. This type has been touched upon in ES6, but is truly included in THE ES standard in ES10
const s = Symbol(a)console.log(s) // Symbol()
console.log(s.description) // undefined
Copy the code
const s = Symbol('lilei')
console.log(s) // Symbol(lilei)
console.log(s.description) // lilei
s.description = 'hanmeimei'
console.log(s.description) // Lilei cannot be assigned, but can only be fetched
Copy the code