π£
19μΌμ°¨
Part 3. JavaScript Essentials
Ch 3. JS ν¨μ
ch 4. JS ν΄λμ€
Ch 3. JS ν¨μ
μ£Όμ
- ν¨μ κΈ°λ³Έ λ¬Έλ²
μ£Όμ λ΄μ©
ν¨μκ° νΈμΆλλ νμλ₯Ό μ΅λν μ€μΈλ€.
π νμ΄ν ν¨μ => ν¨μ μ΅μν!
const double = function (x) {
return x * 2;
};
console.log("double", double(7));
// const doubleArrow = (x) => {
// return x * 2;
// };
const doubleArrow = x => x * 2;
// const doubleArrow = x => ({
// name: "yujin",
// });
console.log("doubleArrow", doubleArrow(7));
π μ¦μ μ€ν ν¨μ(IIFE, Immediately-Invoked Function Expression)
// (x)()
(function () {
console.log(a * 2);
})();
// (x())
(function () {
console.log(a * 2);
}());
π νΈμ΄μ€ν (Hoisting) : ν¨μ μ μΈλΆκ° μ ν¨λ²μ μ΅μλ¨μΌλ‘ λμ΄μ¬λ €μ§λ νμ
https://devjindev.tistory.com/52?category=926283
=> νλ¨μμ λͺ¨λ ν¨μλ₯Ό μ μΈνκ³ , μλ¨μμ ν¨μλ₯Ό νΈμΆν λ μ΄μ κ°μ μ리λ₯Ό μ¬μ© => 보기 μ’λ€
π νμ΄λ¨Έ ν¨μ
- setTimeout(ν¨μ, μκ°): μΌμ μκ° ν ν¨μ μ€ν
- setInterval(ν¨μ, μκ°): μκ° κ°κ²©λ§λ€ ν¨μ μ€ν
- clearTimeout(): μ€μ λ Timeout ν¨μλ₯Ό μ’ λ£
- clearInterval(): μ€μ λ Interval ν¨μλ₯Ό μ’ λ£
π μ½λ°±(Callback) : ν¨μμ μΈμλ‘ μ¬μ©λλ ν¨μ
'νΉμ ν μ€ν μμΉλ₯Ό 보μ₯ν΄μ€λ€'
μλ‘κ² μκ² λ λ΄μ©
π arguments
Ch 4. ν΄λμ€
μ£Όμ
- ν΄λμ€ κΈ°λ³Έ λ¬Έλ²
μ£Όμ λ΄μ©
for μ½λ(ν¨μ) μ€λ³΅ λ°©μ§, ν¨μ¨μ μΈ λ©λͺ¨λ¦¬ μ¬μ©
π μμ±μ ν¨μ(prototype)
prototypeμ ν΅ν΄ μ§μ ν λ©μλλ λ©λͺ¨λ¦¬μ ν λ²λ§ λ§λ€μ΄ μ§κ³ , μ΄κ²μ μμ μλ μμ±μκ° μΈμ λ μ§ νμ©ν μ μλ€.
function User(first, last) {
this.firstName = first;
this.lastName = last;
}
User.prototype.getFullName = function () {
return `${this.firstName} ${this.lastName}`;
};
const heropy1 = new User("Yujin1", "Hong1");
const heropy2 = new User("Yujin2", "Hong2");
const heropy3 = new User("Yujin3", "Hong3");
console.log(heropy1.getFullName());
console.log(heropy2.getFullName());
console.log(heropy3.getFullName());
https://devjindev.tistory.com/58?category=926283
π this
- μΌλ°(Normal) ν¨μλ νΈμΆ μμΉμ λ°λΌ this μ μ
- νμ΄ν(Arrow) ν¨μλ μμ μ΄ μ μΈλ ν¨μ λ²μμμ this μ μ
https://devjindev.tistory.com/54?category=926283
const heropy = {
name: "Yujin",
normal: function () {
console.log(this.name);
},
arrow: () => {
console.log(this.name);
},
};
heropy.normal(); // Yujin
heropy.arrow(); // undefined
const amy = {
name: "amy",
normal: heropy.normal,
arrow: heropy.arrow,
};
amy.normal(); // Amy
amy.arrow(); // undefined
π ES6 Classes
// function User(first, last) {
// this.firstName = first;
// this.lastName = last;
// }
// User.prototype.getFullName = function () {
// return `${this.firstName} ${this.lastName}`;
// };
class User {
constructor(first, last) {
this.firstName = first;
this.lastName = last;
}
getFullName() {
return `${this.firstName} ${this.lastName}`;
}
}
const heropy1 = new User("Yujin1", "Hong1");
const heropy2 = new User("Yujin2", "Hong2");
const heropy3 = new User("Yujin3", "Hong3");
console.log(heropy1.getFullName());
console.log(heropy2.getFullName());
console.log(heropy3.getFullName());
π μμ(νμ₯)
class Vehicle {
constructor(name, wheel) {
this.name = name;
this.wheel = wheel;
}
}
const myVehicle = new Vehicle("μ΄μ‘μλ¨", 2);
console.log(myVehicle);
class Bicycle extends Vehicle {
constructor(name, wheel) {
super(name, wheel);
}
}
const myBicycle = new Bicycle("μΌμ²λ¦¬", 2);
const daughtersBicycle = new Bicycle("μΈλ°", 3);
console.log(myBicycle);
console.log(daughtersBicycle);
class Car extends Vehicle {
constructor(name, wheel, license) {
super(name, wheel);
this.license = license;
}
}
const myCar = new Car("λ²€μΈ ", 4, true);
const daughtersCars = new Car("ν¬λ₯΄μ", 4, false);
console.log(myCar);
console.log(daughtersCars);
μλ‘κ² μκ² λ λ΄μ©
μ νμ΄ν ν¨μμμ thisκ° μμ μ€μ½νλ₯Ό κ°λ¦¬ν¨λ€λ κ°λ μ΄ μ μ΄ν΄κ° μ λμλλ°
const timer = {
name: "Heropy!!",
timeout: function () {
setTimeout(function () {
console.log(this.name);
}, 2000);
},
};
timer.timeout();
μ΄ μνμμλ undefinedκ° μΆλ ₯λλ€. μ½λ°±(μΌλ°)ν¨μμμ thisλ νΈμΆ μμΉμ λ°λΌ κ²°μ λλλ°, κ·Έ μμΉκ° timeoutμ΄ μλ setTimeout λ΄λΆμ μκΈ° λλ¬Έμ undefinedλ₯Ό κ°λ¦¬ν¨λ€.
const timer = {
name: "Heropy!!",
timeoue: function () {
setTimeout(() => {
console.log(this.name);
}, 2000);
},
};
timer.timeout();
μΌλ°ν¨μ λ§κ³ νμ΄ν ν¨μλ₯Ό μ¨μ£Όλ©΄ λΉλ‘μ Heropy!! κ° μΆλ ₯λλ€. νμ΄ν ν¨μμμ thisλ μμ μ΄ μ μΈλ ν¨μ λ²μμμ κ²°μ λκΈ° λλ¬Έμ, setTimeout λ²μμΈ timerλ₯Ό κ°λ¦¬ν¬ μ μλ κ²μ΄λ€. κ·Έλμ μμ μ€μ½νλ₯Ό κ°λ¦¬ν¨λ€κ³ λ§ ν μ μμλ κ²μ΄λ€!!!!!
λλμ
κΈ°μ λ©΄μ 곡λΆνλλΌ κ·Έλμ λΈλ‘κ·Έμ μ 리 ν΄λ κ²λ€μ΄ λ§μ΄ λμλλ κ°μμλ€ (λΏλ―)
λΈλ‘κ·Έμ μ 리νλ©΄μ 곡λΆν λλ κ·Έλ κ³ , 'λͺ¨λ μλ°μ€ν¬λ¦½νΈ Deep Dive' λΌλ μ±
μΌλ‘ JS μ€ν°λλ₯Ό ν μ μ΄ μλλ° μ΄ μ±
μμ prototypeμ κ΅μ₯ν κΈΈκ³ κΉκ² μ€λͺ
ν΄μ€μ λ무 μ΄λ €μ μλ€π’ κ·Όλ° μ€λ κ°μ λ€μΌλ©΄μ μ§μ μμ±μΌλ‘ λ£κ³ μμλ λ³΄κ³ μ½λ©λ μ§μ ν΄λ΄μ κ·Έλ°κ±΄μ§ μ¬μ΄λ€ λ¨Ήμ κ²μ²λΌ μ΄ν΄κ° λλ κ²λ€μ΄ λ§μλ€. κ·Έλμ μ€λ μ±λ¦°μ§ κΈλ μ΄μ¬ν μ μ± λ€μ¬ μ΄ κ² κ°λ€γ
γ
γ
γ
γ
γ
γ
γ
(μλκΈμΌλ‘ κΈΈκ² μ΄ λ―)
νκ΅ μμ μμ μλ°λ₯Ό μ¬λ°κ² νμλλ° μ μ¨ λ²λ¦ νλ€ λ³΄λ ν΄λμ€κ° νμ λ―μ€κ² λκ»΄μ§λ€.... μ°λ¦¬ μΉν΄μ§μ
λ³Έ ν¬μ€ν μ ν¨μ€νΈμΊ νΌμ€ νκΈ μ±λ¦°μ§ μ°Έμ¬λ₯Ό μν΄ μμ±λμμ΅λλ€.
#ν¨μ€νΈμΊ νΌμ€
#ν¨μΊ μ±λ¦°μ§
#μ§μ₯μΈμΈκ°
#μ§μ₯μΈμκΈ°κ³λ°
#ν¨μ€νΈμΊ νΌμ€νκΈ°
#ν_λ²μ_λλ΄λ_νλ‘ νΈμλ_κ°λ°_μ΄κ²©μ°¨_ν¨ν€μ§_Online
'π¬ > γ γ γ γ γ γ μ±λ¦°μ§' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
20μΌμ°¨ (0) | 2022.02.14 |
---|---|
γ γ γ γ γ γ μ±λ¦°μ§ μ€ν¨νλμ,,,,,,,,, λ°νν,,,,,,,,,,,,,,,, ππ€£π π₯ππ’ππ²π¨π°π±π₯Άπ¦π¦π¦ (0) | 2022.02.13 |
ν¨μ€νΈμΊ νΌμ€ μ±λ¦°μ§ 18μΌμ°¨ (0) | 2022.02.10 |
ν¨μ€νΈμΊ νΌμ€ μ±λ¦°μ§ 17μΌμ°¨ (0) | 2022.02.09 |
ν¨μ€νΈμΊ νΌμ€ μ±λ¦°μ§ 16μΌμ°¨ (0) | 2022.02.08 |