Shallow Copying Objects:

  • Will duplicate the top-level properties but nested object is shared between original and the copy
  • Array.prototype.slice()
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    const arr = ['peanut''butter''and''jelly'];
     
    arr.slice(1); // ['butter', 'and', 'jelly']
    arr.slice(01); // ['peanut']
    arr.slice(02); // ['peanut', 'butter']
    arr.slice(22); // []
    arr.slice(220); // ['and', 'jelly']
    arr.slice(30);// []
    arr.slice(3100);// ['jelly']
    arr.slice(51); // []
    cs
  • Object.assgin()
    • Object.assign({}, arr)
  • will affect 'array inside array' if it modifies since it is shallow copying objects
  • Pitfall: ๊ณ„์† ์ˆœํ™˜ ์ฐธ์กฐ

Deep Copying Objects:

  • JSON.parse(JSON.stringify(object))
  • Pitafall: if you put user's method, it will cause an error.
  • ์„œ๋ฒ„ ํ†ต์‹ ์—์„œ๋Š” ๋”ฎ์นดํ”ผ๊ฐ€ ๋งž์Œ
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๊ฐ์ฒด๋‚˜ ๋ฐฐ์—ด์ด ์•„๋‹ˆ๋ผ ๊ทธ๋ƒฅ ๊ธ€์ž์ž„

 

 

 

reference:

https://scotch.io/bar-talk/copying-objects-in-javascript

https://medium.com/watcha/๊นŠ์€-๋ณต์‚ฌ์™€-์–•์€-๋ณต์‚ฌ์—-๋Œ€ํ•œ-์‹ฌ๋„์žˆ๋Š”-์ด์•ผ๊ธฐ-2f7d797e008a

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Lexical Scope  (0) 2020.11.04
HOISTING  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
How to calculate number easily in Javascript  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27

From ๋ชจ๊ฐ์ฝ”...

 

Scope๋Š” ์ฒด์ธ์œผ๋กœ ์—ฐ๊ฒฐ์ด ๋˜์–ด ์žˆ์Œ

 

์ „์—ญ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ๊ฐ€ ์žˆ์œผ๋ฉด, ๊ทธ๊ฒƒ์€ lexical environment๋ฅผ ๋ฐ”๋ผ๋ณด๊ณ  ์ฐธ์กฐํ•˜๊ณ  ์žˆ๊ณ , ๊ทธ๊ฒƒ์ด ์ฃฝ์ง€ ์•Š๋Š” ํ•œ lexical environment๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Lexical enviornmentํ•œํ…Œ๋Š” ์ง„์งœ ์ž๊ธฐ ํ™˜๊ฒฝ์„ ์—ฐ๊ฒฐํ•œ ์†์„ฑ์ด ์žˆ๊ณ  outer lexical environment (์ƒ์œ„ ์Šค์ฝ”ํ”„)๋ฅผ ๊ธฐ์–ตํ•˜๊ณ  ์žˆ์Œ.

๊ฒฐ๊ตญ, ์ž๊ธฐ ์ƒ์œ„๊ฐ€ ๋ˆ„๊ตฐ์ง€ ๊ธฐ์–ตํ•˜๊ณ  ์ฐธ์กฐํ•ด์•ผํ•  ํ™˜๊ฒฝ์„ ์ฐธ์กฐํ•˜๊ณ  ์žˆ์Œ.

 

์‹คํ–‰ context scope์€ ์Šคํƒ ๊ตฌ์กฐ๋กœ ์Œ“์•„์ ธ ๋‚˜๊ฐ€๊ณ , ๋งจ ๋ฐ‘ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ ์œ„์— ํ•จ์ˆ˜์˜ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ๊ฐ€ ์Œ“์ด๊ฒŒ ๋œ๋‹ค.

 

์ „์—ญ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ๊ฐ€ ๋ ‰์‹œ์ปฌ ํ™˜๊ฒฝ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Œ ์ „์—ญ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ ๋ฐ‘์— ์˜ฌ๋ผ์˜ค๋ฉด outer lexical reference environment๊ฐ€ ์‹ค์ œ ์‹๋ณ„์ž๊ฐ€ ์žˆ๋Š” ๊ณต๊ฐ„์„ ์ €์žฅํ•จ

 

์•ˆ์— ๋ณ€์ˆ˜๊ฐ€ ์—†์„ ๋•Œ ์ƒ์œ„์— ๋ณ€์ˆ˜๊ฐ€ ํ˜ธ์ถœ์ด ๋  ๋•Œ, ์ƒ์œ„ ์Šค์ฝ”ํ”„๋ฅผ ์ฐธ์กฐํ•˜๊ฒŒ ๋จ

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ํ•จ์ˆ˜๊ฐ€ ์ƒ์„ฑ์ด ๋  ๋•Œ ์ƒ์œ„ ์Šค์ฝ”ํ”„๊ฐ€ ๋ˆ„๊ตฌ์ธ ์ง€ ํ™•์ธํ•จ ๊ทธ๋ž˜์„œ lexical scope๋กœ ์ •ํ•ด๋†“์Œ

 

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Shallow vs. Deep Copying Objects  (0) 2020.11.05
HOISTING  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
How to calculate number easily in Javascript  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27

From ๋ชจ๊ฐ์ฝ”...

 

ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋Š” interpreter language and compile language๋กœ ๋‚˜๋ˆ„์–ด์ง.

 

JavaScript๋Š” interpreter language์ด๊ธฐ์—, ์œ„์—์„œ๋ถ€ํ„ฐ ํ•œ ์ค„์”ฉ ์ฝ๊ฒŒ ๋จ(๋Ÿฐํƒ€์ž„). ๊ทธ๋ฆฌ๊ณ , ๋Ÿฐํƒ€์ž„ ์ด์ „์— ๋ฌธ์„œ๋ฅผ ํ•œ ๋ฒˆ ์ฝ์–ด์„œ ์„ ์–ธ๋ฌธ์ด ์žˆ์œผ๋ฉด ๊ณต๊ฐ„์„ ๋จผ์ € ๋งŒ๋“ค์–ด ์คŒ.

 

์„ ์–ธ๋ฌธ์„ ์•ž์œผ๋กœ ๋Œ์–ด์„œ ํ˜ธ์ด์ŠคํŒ… ํ•˜๋Š” ๊ฒƒ์€ lexical environment์ž„

 

์œˆ๋„์šฐ ๊ฐ์ฒด์— ์ „์—ญ๋ณ€์ˆ˜๊ฐ€ ์ €์žฅ์ด ๋˜๊ณ , ๋จผ์ € ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์ด ๋งŒ๋“ค์–ด ์ง. ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋ฅผ ๋งŒ๋“ค๊ณ , ํ• ๋‹น์ด ๋‹นํ–ˆ์„ ๋•Œ ์ €์žฅ์ด ๋จ.

 

ํ• ๋‹น๋ฌธ์„ ๋งŒ๋‚˜์•ผ๋งŒ ์šฐ๋ณ€์ด ์ƒ์„ฑ๋˜๋ฉฐ ์šฐ๋ณ€์˜ ๊ฐ’์ด ํ‰๊ฐ€๊ฐ€ ๋˜๊ณ , ์˜ค๋ฅธ์ชฝ์—์„œ ํ‰๊ฐ€ํ•ด์„œ ์™ผ์ชฝ์œผ๋กœ ๋„ฃ์Œ.

 

์„ ์–ธ๋ฌธ์€ ๋Ÿฐํƒ€์ž„์ด์ „์— ์„ ์–ธ๋œ ๋ชจ๋“  ๊ฒƒ์„ ์•ž์ชฝ์—์„œ ์„ ์–ธ๋˜๋Š” ํ˜ธ์ด์ŠคํŒ…์ด ์ผ์–ด๋‚จ.

 

ํ‘œํ˜„์‹์€ ํ• ๋‹น๋ฌธ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋Ÿฐํƒ€์ž„์— ์ƒ์„ฑ์ด ๋˜๋ฉฐ ํ˜ธ์ด์ŠคํŒ…์ด ์•ˆ์ผ์–ด๋‚˜๋‹ˆ๊น ์“ฐ๊ธฐ ๋” ๋‚˜์Œ

 

๋ณ€์ˆ˜์— ๊ฐ’์ด ๋“ค์–ด๊ฐ€๋Š” ๊ฑฐ์—์„œ ํ•จ์ˆ˜๊ฐ€ ๋ณ€์ˆ˜์— ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ๋„ ํ• ๋‹น์ด๊ธฐ์— ๋Ÿฐํƒ€์ž„์— ์ƒ๊น€. ์˜ˆ๋ฅผ ๋“ค์–ด, const a= function()

 

์ˆœ์„œ์— ๋งž๊ฒŒ ์ ์–ด๋ผ! ๋ฐ‘์— ํ• ๋‹นํ•œ ๊ฒƒ์„ ์œ„์—์„œ ์“ฐ์ง€ ๋งˆ๋ผ. ํ˜ธ์ด์ŠคํŒ…์„ ์•…์šฉํ•˜์ง€ ๋ง์ž.

 

more details:

joshua1988.github.io/web-development/javascript/function-expressions-vs-declarations/

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Shallow vs. Deep Copying Objects  (0) 2020.11.05
Lexical Scope  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
How to calculate number easily in Javascript  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27
  • A tool that you can find specific word in String
  • comfile
    1
    2
    var pattern = /p/
    var pattern = new RegExp('p');
    c
  • exec
    1
    2
    console.log(pattern.exec('paige')); // ["p"]
    console.log(pattern.exec('aige')); // null
    cs
  • test
    • returns as Boolean
      1
      2
      console.log(pattern.test('paige')); // true
      console.log(pattern.test('aige')); // false
      cs
  • STRING METHOD
    • match
      1
      2
      console.log('paige'.match(pattern)); // ["p"]
      console.log('aige'.match(pattern)); // null
      cs
    • replace
      1
      console.log('paige'.replace(pattern, 'P'));  // Paige
      cs
  • OPTION
    • i : does not care whether uppercase or lowercase
      1
      2
      3
      4
      var xi = /p/;
      console.log("Paige".match(xi)); // null
      var oi = /p/i;
      console.log("Paige".match(oi)); // ["P"];
      cs
    • g: returns all the result
      1
      2
      3
      4
      var xg = /p/;
      console.log("Paige".match(xg)); // null
      var og = /p/g;
      console.log("Paige".match(og)); // ["P"];
      cs
    • ig : can find all result whether uppercase or lowercase
      1
      2
      var ig = /p/ig;
      "Paigepaige".match(ig); // ["P", "p"]
      cs
  • CAPTURE
    • \w : you are getting words from A~Z, a~z, 0~9
    • + : more than one value 
    • \s : represents space
      1
      2
      3
      var pattern = /(\w+)\s(\w+)/;
      var str = "Paige Kim";
      var result = str.replace(pattern, "$2, $1"); // "Kim, Paige"
      cs
  • REPLACE
    1
    2
    3
    4
    5
    6
    var urlPattern = /\b(?:https?):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*/gim;
    var content = 'github : https://github.com/paigekim29 ์ž…๋‹ˆ๋‹ค. 
    tistory : https://paigekim29.tistory.com/ ์ž…๋‹ˆ๋‹ค. '
    ;
    var result = content.replace(urlPattern, function(url){
        return '<a href="'+url+'">'+url+'</a>';
    });
    console.log(result); // github : <a href="https://github.com/paigekim29">
    https://github.com/paigekim29</a> ์ž…๋‹ˆ๋‹ค.
    tistory : <a href="https://paigekim29.tistory.com/">
    https://paigekim29.tistory.com/</a> ์ž…๋‹ˆ๋‹ค.
      cs

 

 

reference: https://opentutorials.org/course/743/6580

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Lexical Scope  (0) 2020.11.04
HOISTING  (0) 2020.11.04
How to calculate number easily in Javascript  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27
isNaN(is Not a Number)  (0) 2020.10.27
1
2
3
minute = minute +1;
minute += 1;
minute ++;
cs

reference: https://www.w3schools.com/js/js_arithmetic.asp

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

HOISTING  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27
isNaN(is Not a Number)  (0) 2020.10.27
How to use Color Scripter in Tistory  (0) 2020.10.26
  • refresh : command + r
  • command + d : to select same items continuously
  • command + control + space : emoji ๐Ÿ˜œ

VSC

  • option + click : to click line you want
  • option + โ†‘/โ†“ : move items up and down
  • option + shift + โ†‘/โ†“: to copy up and down
  • command + / : to remark
  • option + shift + i : can put cursor with all selection
  • option + shift+ drag : can put cursor where your mouse is at so it is helpful when you want to select lines with different lengths of codes
  • command + โ†‘/โ†“ : to go to top and bottom
  • command + b: to remove sidebar

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

HOISTING  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
How to calculate number easily in Javascript  (0) 2020.10.28
isNaN(is Not a Number)  (0) 2020.10.27
How to use Color Scripter in Tistory  (0) 2020.10.26
  1. -infinity / - infinity = NaN
  2. 0 / 0 =NaN

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

HOISTING  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
How to calculate number easily in Javascript  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27
How to use Color Scripter in Tistory  (0) 2020.10.26

ํ‹ฐ์Šคํ† ๋ฆฌ ์—…๋ฐ์ดํŠธ ์ดํ›„, ์†Œ์Šค ์ฝ”๋“œ ์ด์šฉ ๋ฐฉ๋ฒ•

 

reference: https://gabii.tistory.com/entry/Tistory-Blog-%EB%B0%94%EB%80%90-Color-Scripter-%EB%B3%B5%EC%82%AC-%EB%B0%A9%EB%B2%95-%EC%82%AC%EC%9A%A9

'Today's Finding' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

HOISTING  (0) 2020.11.04
Regular Expressions(์ •๊ทœํ‘œํ˜„์‹)  (0) 2020.10.28
How to calculate number easily in Javascript  (0) 2020.10.28
Shortcut in Mac  (0) 2020.10.27
isNaN(is Not a Number)  (0) 2020.10.27

+ Recent posts