๐ŸŸจ JavaScript

    [mdn, ๋“œ๋ฆผ์ฝ”๋”ฉ ์™ธ] ๊ฐ์ฒด์ง€ํ–ฅ (4) : ํด๋ž˜์Šค์˜ ์ƒ์† (sub classing)

    ํด๋ž˜์Šค์˜ ์ƒ์† (sub classing) class Goodcoder { constructor(age, lang, address) { this.age = age; this.lang = lang; this.address = address; } coding() { console.log(`๋‚ด๊ฐ€ ๊ณต๋ถ€์ค‘์ธ ์–ธ์–ด๋Š” ${this.lang}์ž…๋‹ˆ๋‹ค.`) } } ์ด ์•„๋ž˜์— ์ƒˆ๋กœ์šด ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์€๋ฐ, class Goodcoder์˜ ๊ฐ’์„ ์ƒ์†์‹œํ‚ค๊ณ  ์‹ถ๋‹ค๋ฉด extends๋ฅผ ๋„ฃ์–ด ๊ฐ„๋‹จํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. class Employee extends Goodcoder {} ์ด๋ ‡๊ฒŒ ์ƒˆ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด extends๋กœ ์ƒ์†์„ ํ•˜๋ฉด, ์ƒˆ๋กœ์šด ํด๋ž˜์Šค์— ์ด์ „ ํด๋ž˜์Šค ๊ฐ’๋“ค์ด ์ƒ์†๋œ๋‹ค. const noran = new Employee(20..

    [mdn, ๋“œ๋ฆผ์ฝ”๋”ฉ ์™ธ] ๊ฐ์ฒด์ง€ํ–ฅ (3) : ์ •์  ์†์„ฑ๊ณผ ๋ฉ”์†Œ๋“œ(static properties and methods)

    ์ •์  ์†์„ฑ๊ณผ ๋ฉ”์†Œ๋“œ(static properties and methods) static ํ‚ค์›Œ๋“œ๋ฅผ ๋ถ™์ด๋ฉด ํ”„๋กœํผํ‹ฐ๋‚˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ์ธ์Šคํ„ด์Šคํ™”๋˜์ง€ ์•Š๊ณ  ํด๋ž˜์Šค ์ž์ฒด์— ๋ถ™๋Š”๋‹ค. class goodCoder { static codername = 'noran'; constructor(coderNumber) { this.coderNumber = coderNumber; } static printCoder() { console.log(goodCoder.codername); } } const coder1 = new goodCoder(1); const coder2 = new goodCoder(2); console.log(coder1.codername); //undefined ์œ„ ์ฝ”๋“œ์—์„œ console.log(coder1.cod..

    [mdn, ๋“œ๋ฆผ์ฝ”๋”ฉ ์™ธ] ๊ฐ์ฒด์ง€ํ–ฅ (2) : ๊ฐ์ฒด(object)์™€ getter and setter

    ๊ฐ์ฒด(object) https://sunshineyellow.tistory.com/17 [์ฝ”๋”ฉ์•™๋งˆ ์™ธ] ๊ฐ์ฒด(Object)์™€ ํ”„๋กœํผํ‹ฐ(property) ๊ฐ์ฒด(Object) key์™€ value๋กœ ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์žˆ๋‹ค. 1. ํ•จ์ˆ˜ํ‘œํ˜„์‹ const goodCoder = function(name, age, coding) { name : 'Noran', age : 20, coding : function(){ console.log('ํ™”์ดํŒ…!'); } } name : 'Noran',.. sunshineyellow.tistory.com ์œ„ ๊ธ€์—์„œ ์ž ๊น ์งš๊ณ  ๋„˜์–ด๊ฐ„ ๊ฐ์ฒด๋ฅผ ํด๋ž˜์Šค์™€ ํ•จ๊ป˜ ์‹ฌํ™”ํ•™์Šตํ•œ๋‹ค. class Goodcoder { //constructor constructor(name, age) { this.name = ..

    [mdn, ๋“œ๋ฆผ์ฝ”๋”ฉ ์™ธ] ๊ฐ์ฒด์ง€ํ–ฅ (1) : ํด๋ž˜์Šค(class)

    ๋“ค์–ด๊ฐ€๊ธฐ ์•ž์„œ : ์ƒ์„ฑ์žํ•จ์ˆ˜์™€ ํด๋ž˜์Šค์˜ ์ฐจ์ด์  https://sunshineyellow.tistory.com/18?category=1037372 [์ฝ”๋”ฉ์•™๋งˆ ์™ธ] ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด๊ณผ ๊ฐ์ฒด ์ ‘๊ทผ๋ฒ•, ๊ทธ๋ฆฌ๊ณ  ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ๋‹จ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋งŒ์„ ์ƒ์„ฑํ•  ๋•Œ๋Š” ์ง๊ด€์ ์ด๊ณ  ๊ฐ„ํŽธํ•œ ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์„ ์‚ฌ์šฉํ•˜๊ณ , ๊ฐ™์€ ๊ฐ์ฒด๋ฅผ ๋Œ€๋Ÿ‰์ƒ์‚ฐํ•  ๋•Œ๋Š” ์ƒ์„ฑ์žํ•จ์ˆ˜๋ฅผ sunshineyellow.tistory.com ์œ„ ๊ธ€์—์„œ ๊ฐ์ฒด์™€ ์ƒ์„ฑ์žํ•จ์ˆ˜๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ณต๋ถ€ํ–ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ƒ์„ฑ์žํ•จ์ˆ˜์™€ ๋‹ค๋ฅธ ํด๋ž˜์Šค์˜ ํŠน์ด์ ์€ ๋ฌด์—‡์ผ๊นŒ? ํด๋ž˜์Šค๋Š” new ์—ฐ์‚ฐ์ž ์—†์ด๋Š” ํ˜ธ์ถœ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ํด๋ž˜์Šค๋Š” extends(ํด๋ž˜์Šค์˜ ์ƒ์†)์™€ super(superํด๋ž˜์Šค์˜ constructor๊ณผ method ํ˜ธ์ถœ)๋ฅผ ..

    [๋“œ๋ฆผ์ฝ”๋”ฉ] IIFE (์ฆ‰์‹œ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ)

    function sayHello(){ console.log('Hello'); } sayHello(); ์ฆ‰์‹œ ํ˜ธ์ถœ๋˜์–ด์•ผ ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค ๊ฒฝ์šฐ ์•„๋ž˜์ฒ˜๋Ÿผ ํ•œ๋ฒˆ ๋” ํ˜ธ์ถœํ•ด์ค˜์•ผ ํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์ด ์žˆ๋‹ค. ์ด๋ฅผ IIFE (Immediately Invoked Function Expression)์„ ํ†ตํ•ด ๋” ์‰ฝ๊ฒŒ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค. (function sayHello(){ console.log('Hello'); })(); ํ•จ์ˆ˜๋ฅผ ()๊ด„ํ˜ธ๋กœ ๊ฐ์‹ธ๊ณ  ();๋ฅผ ๋ถ™์ด๋ฉด ๋œ๋‹ค.

    [๋“œ๋ฆผ์ฝ”๋”ฉ] ๋””๋ฒ„๊น… ํŒ - named function, recursions

    * named function์€ class์™€ object์— ๊ด€ํ•œ ๊ฐœ๋…์ •๋ฆฌ ๊ฒŒ์‹œ๊ธ€์—์„œ ํ•œ๋ฒˆ ๋” ์–ธ๊ธ‰ํ•œ๋‹ค. const printGood = function () { console.log('Good'); } ์ผ๋ฐ˜์ ์ธ ์ด๋Ÿฐ ํ•จ์ˆ˜์„ ์–ธ๋ฌธ์—์„œ, function ์˜†์— ์ด๋ฆ„์„ ๋ถ™์—ฌ์ฃผ์–ด (named function) ๋””๋ฒ„๊น…ํ•  ๋•Œ ํ•จ์ˆ˜ ์ด๋ฆ„์ด ๋‚˜์™€์„œ ๋””๋ฒ„๊น…์„ ๋” ์†์‰ฝ๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค. const printGood = function print() { console.log('Good'); } ํ•จ์ˆ˜ ์•ˆ์—์„œ ํ•จ์ˆ˜๋ฅผ ๋ถ€๋ฅด๋Š” recursions๋„ ๋””๋ฒ„๊น… ์‹œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. (๋ฐ˜๋ณต๋˜๋Š” ํ‰๊ท ๊ฐ’์„ ๊ณ„์‚ฐํ•˜๋Š” ๋“ฑ์˜ ๊ฒฝ์šฐ์— ์‚ฌ์šฉ) const printGood = function print() { console.log('Good'); print..