λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

πŸ’¬/γ…γ……γ…Œγ…‹γ…γ…… μ±Œλ¦°μ§€

패슀트캠퍼슀 μ±Œλ¦°μ§€ 19일차

🍣

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

 

[JavaScript] ν˜Έμ΄μŠ€νŒ…(Hoisting) μ΄λž€?

πŸ”— ν˜Έμ΄μŠ€νŒ…(Hoisting)μ΄λž€?  λ³€μˆ˜ λ˜λŠ” ν•¨μˆ˜ μ„ μ–Έ 뢀뢄이 μ΅œμƒλ‹¨μœΌλ‘œ λŒμ–΄ μ˜¬λ €μ§€λŠ” ν˜„μƒμ„ μ˜λ―Έν•œλ‹€.  λ³€μˆ˜κ°€ 있으면 μœ„μΉ˜μ— 상관없이 μ΅œμƒλ‹¨μ—μ„œ undefined된 ν˜•νƒœλ‘œ μ‘΄μž¬ν•œλ‹€. ⭐ 주의  var λ³€μˆ˜

devjindev.tistory.com

=> ν•˜λ‹¨μ—μ„œ λͺ¨λ“  ν•¨μˆ˜λ₯Ό μ„ μ–Έν•˜κ³ , μƒλ‹¨μ—μ„œ ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•  λ•Œ 이와 같은 원리λ₯Ό μ‚¬μš© => 보기 μ’‹λ‹€

 

 πŸ”— 타이머 ν•¨μˆ˜ 

  • 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());

 

prototype

https://devjindev.tistory.com/58?category=926283 

 

[JavaScript] ν”„λ‘œν† νƒ€μž…(prototype) μ΄λž€

 ν΄λž˜μŠ€(class)λŠ” 객체지ν–₯μ–Έμ–΄μ—μ„œ 빠질 수 μ—†λŠ” κ°œλ…μ΄λ‹€. μžλ°”μŠ€ν¬λ¦½νŠΈλ„ 객체지ν–₯언어이닀. ν•˜μ§€λ§Œ μžλ°”μŠ€ν¬λ¦½νŠΈμ—λŠ” ν΄λž˜μŠ€κ°€ μ—†λ‹€. λŒ€μ‹  ν”„λ‘œν† νƒ€μž…μ΄λΌλŠ” 것이 μ‘΄μž¬ν•œλ‹€. 이것이 μžλ°”μŠ€

devjindev.tistory.com

 

 πŸ”— this 

  • 일반(Normal) ν•¨μˆ˜λŠ” 호좜 μœ„μΉ˜μ— 따라 this μ •μ˜
  • ν™”μ‚΄ν‘œ(Arrow) ν•¨μˆ˜λŠ” μžμ‹ μ΄ μ„ μ–Έλœ ν•¨μˆ˜ λ²”μœ„μ—μ„œ this μ •μ˜

https://devjindev.tistory.com/54?category=926283

 

[JavaScript] thisλž€? / call, apply, bind 차이점

πŸ”— thisλž€?  thisλŠ” ν•¨μˆ˜ 호좜 방식에 따라 this에 바인딩할 객체가 λ™μ μœΌλ‘œ κ²°μ •λœλ‹€. (μ˜ˆμ™Έμ μœΌλ‘œ, bind ν•¨μˆ˜λŠ” 호좜과 λ¬΄κ΄€μ—κ²Œ λ¬Άμ–΄μ„œ κ³ μ •μ‹œν‚¬ 수 μžˆλ‹€.) ν˜ΈμΆœν•œ 객체 === this πŸ”— ν•¨μˆ˜ 호좜 λ°©

devjindev.tistory.com

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

 

this

 

 πŸ”— 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

 

https://bit.ly/37BpXiC

 

패슀트캠퍼슀 [직μž₯인 μ‹€λ¬΄κ΅μœ‘]

ν”„λ‘œκ·Έλž˜λ°, μ˜μƒνŽΈμ§‘, UX/UI, λ§ˆμΌ€νŒ…, 데이터 뢄석, μ—‘μ…€κ°•μ˜, The RED, ꡭ비지원, κΈ°μ—…κ΅μœ‘, μ„œλΉ„μŠ€ 제곡.

fastcampus.co.kr