ES6에 추가 된 것들
아래 URL 의 정보를 보기 내가 보기에 편하게 옮겨 적은 글
참고
-
const
- Constants
const PI = 3.141593
- let과 const 는 중괄호(“{}”)로 정의된 블록으로 유효 범위(스코프)를 지정하는 새로운 var 이다
- var 는 전역 또는 함수 내부로 유효 범위를 갖는다
- var 호이스팅(hoisting)
- 변수 선언이 함수 또는 전역 코드의 상단에 이동하는 것과 같은 행동을 “호이스팅(hoisting)”이라고 불립니다.
-
scope
- Block-Scoped Variables
- Block-scoped variables (and constants) without hoisting.
- Block-Scoped Functions
- Block-scoped function definitions.
- Block-Scoped Variables
-
arrow function
- Expression Bodies
- More expressive closure syntax
map(v => v + 1)
- More expressive closure syntax
- Statement Bodies
- More expressive closure syntax
- Lexical this
- More intuitive handling of current object context.
- Expression Bodies
-
Extended Parameter Handling
-
Template Literals
- String Interpolation
- Custom Interpolation
- Raw String Access
-
Extended Literals
- Binary & Octal Literal
- Unicode String & RegExp Literal
-
Enhanced Regular Expression
- Regular Expression Sticky Matching
-
Enhanced Object Properties
- Property Shorthand
- Computed Property Names
- Method Properties
-
Destructuring Assignment
- Array Matching
- Object Matching, Shorthand Notation
- Object Matching, Deep Matching
- Object And Array Matching, Default Values
- Parameter Context Matching
- Fail-Soft Destructuring
-
Modules
- Value Export/Import
- Default & Wildcard
-
Classes
- Class Definition
- More intuitive, OOP-style and boilerplate-free classes.
- Class Inheritance
- More intuitive, OOP-style and boilerplate-free inheritance.
- Class Inheritance, From Expressions
- Base Class Access
super.xxx
- Static Members
- Getter/Setter
- Class Definition
- Symbol Type
- Symbol Type
Symbol('foo') !== Symbol('foo') const foo = Symbol() const bar = Symbol() typeof foo === 'symbol' typeof bar === 'symbol' let obj = {} obj[foo] = 'foo' obj[bar] = 'bar' JSON.stringify(obj) // {} Object.keys(obj) // [] Object.getOwnPropertyNames(obj) // [] Object.getOwnPropertySymbols(obj) // [ foo, bar ]
- Global Symbols
Symbol.for('app.foo') === Symbol.for('app.foo')
- Symbol Type
-
Iterators
- Iterator & For-Of Operator
-
Generators
yield
-
Map/Set & WeakMap/WeakSet
- Set Data-Structure
let s = new Set() s.add('hello').add('goodbye').add('hello') s.size === 2 s.has('hello') === true for (let key of s.values()) // insertion order console.log(key)
- Map Data-Structure
let m = new Map() let s = Symbol() m.set('hello', 42) m.set(s, 34) m.get(s) === 34 m.size === 2 for (let [key, val] of m.entries()) console.log(key + ' = ' + val)
- Weak-Link Data-Structures
- Memory-leak-free Object-key’d side-by-side data-structures.
-
Typed Arrays
- Typed Arrays
-
New Built-In Methods
- Object Property Assignment
Object.assign(dest, src1, src2)
- Array Element Finding
;[1, 3, 4, 2] .find(x => x > 3) // 4 [(1, 3, 4, 2)].findIndex(x => x > 3) // 2
- String Repeating
'foo'.repeat(3)
- String Searching
'hello'.startsWith('ello', 1) // true 'hello'.endsWith('hell', 4) // true 'hello'.includes('ell') // true 'hello'.includes('ell', 1) // true 'hello'.includes('ell', 2) // false
- Number Type Checking
Number.isNaN() Number.isFinite()
- Number Safety Checking
Number.isSafeInteger()
- Number Comparison
Number.EPSILON
- Number Truncation
console.log(Math.trunc(42.7)) // 42 console.log(Math.trunc(0.1)) // 0 console.log(Math.trunc(-0.1)) // -0
- Number Sign Determination
-
Promises
- Promise Usage
- Promise Combination
-
Meta-Programming
- Proxying
let target = { foo: 'Welcome, foo', } let proxy = new Proxy(target, { get(receiver, name) { return name in receiver ? receiver[name] : `Hello, ${name}` }, }) proxy.foo === 'Welcome, foo' proxy.world === 'Hello, world'
- Reflection
let obj = {a: 1} Object.defineProperty(obj, 'b', {value: 2}) obj[Symbol('c')] = 3 Reflect.ownKeys(obj) // [ "a", "b", Symbol(c) ]
- Internationalization & Localization
- Collation
- Sorting a set of strings and searching within a set of strings. Collation is parameterized by locale and aware of Unicode.
- Number Formatting
var l10nEN = new Intl.NumberFormat('en-US') var l10nDE = new Intl.NumberFormat('de-DE') l10nEN.format(1234567.89) === '1,234,567.89' l10nDE.format(1234567.89) === '1.234.567,89'
- Currency Formatting
var l10nUSD = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}) l10nUSD.format(100200300.4) === '$100,200,300.40'
- Date/Time Formatting
var l10nEN = new Intl.DateTimeFormat('en-US') l10nEN.format(new Date('2015-01-02')) === '1/2/2015'
- Collation