
ES6 ์๋ก์ด ๋ฌธ๋ฒ ์ ๋ฆฌ
let name="gildong"
let age =17
let cute = true
let person = {name, age, cute}
// let person = {name:name,age:age,cute:cute}์ ๊ฐ๋ค
let person = {
name:"gildong",
age:17,
cute:true
}
let {name, age, cute} = person
/* let name = person.name let age = person.age let cute = person.cute์ ๊ฐ๋ค */
let array = [1,2,3]
let [a,b,c] = array
/* let a = array[0] let b = array[1] let c = array[2]์ ๊ฐ๋ค */
...์ ๋ถ์ธ ๋งค๊ฐ๋ณ์ ํ๋๋ฅผ ์ถ๊ฐํ๋ฉด '๋๋จธ์ง(rest)' ์์๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค.let person = {
name:"gildong",
age:17,
cute:true
}
let {name, ...rest} = person
console.log(rest) // {age:17, cute:true}
let array = [1,2,3]
let [a,...rest] = array console.log(rest)//[2,3]
let a = [1,2]
let b = [3,4]
let c = [5,6]
let result = [...a,...b,...c] // [1,2,3,4,5,6]
let name ="gildong"
console.log(`์ ์ด๋ฆ์ ${name}์
๋๋ค`)
let foo =()=>{
console.log("hello")
}
let zoo =()=>Date.now()
/* function zoo(){
return Date.now()
} ์ ๊ฐ์ */
let koo = (a,b) =>{
let result = a*b
return result
}
//๋๋
let koo = (a,b) =>a*b
//๋ก๋ ํํ ๊ฐ๋ฅ
โํ์ดํ ํจ์๋ฅผ ์ฐ๋ฉด ์๋๋ ๊ฒฝ์ฐ
- object์์ ํจ์ ์ ์์
const person = { points: 23, score: function(){ this.points++; // ์ฌ๊ธฐ์์ ํ์ดํํจ์ ์ฐ๋ฉด point๊ฐ ์ฆ๊ฐ ์ํจ } }
- ํ๋กํ ํ์ ํจ์
class Car { constructor(make, color) { this.make = make; this.color = color; } } let hyundai = new Car("gildong","white") Car.prototype.summary = function () { console.log( `This car is a ${this.make} in the colour ${this.colour}`) } // ์ฌ๊ธฐ์ ํ์ดํํจ์๋ฅผ ์ฐ๋ฉด ์๋๋ค hyundai.summary()
- this
์๋ฐ์คํฌ๋ฆฝํธ์์ ๋ชจ๋ ์ผ๋ฐํจ์๋ ์คํ๋ ๋๋ง๋ค ํจ์ ๋ด๋ถ์ this๋ผ๋ ๊ฐ์ฒด๊ฐ ์ถ๊ฐ๋๋ค. ์ด๋ this๋ ์ด ํจ์๋ฅผ ๋ถ๋ฅธ ๊ฐ์ฒด์ด๋ค.
๋ ํ์ดํ ํจ์๋ ์ผ๋ฐํจ์๋ฅผ ๋์ฒดํ ์ ์๊ณ ํธํ๊ธด ํ์ง๋ง ์๋ ๋ฌธ๋ฒ 100% ๋์ฒํ ์๋ ์๋ค.let age = 20 var obj = { age:12, foo: function () { console.log(this.age) }, }; obj.foo()