전체 글

웹 개발 공부를 위한 블로그입니다.
9-1. `name` property of function class F { static method1 () {} method2 () {} } function G(){ G.method1 = function (){} G.prototype.method2 = function (){} } const f = new F() console.log(F.method1.name, f.method2.name) const g = new G() console.log(G.method1.name, g.method2.name) class에서의 name 프로퍼티만 출력된다. const b = function (){} console.log(b.name) 이것은 name프로퍼티에 b가 출력된다. 그럼 G라는 함수에 대해서 왜 name 프..
7-1. shorthand properties (프로퍼티 축약) 7-1-1. 소개 var x = 10 var y = 20 var obj = { x: x, y: y } const x = 10 const y = 20 const obj = { x, y } shorthand properties는 한번씩만 쓰면 그것이 key이자 value가 된다. 7-1-2. 상세 프로퍼티의 key와 value에 할당할 변수명이 동일한 경우 value 생략 가능. 7-1-3. 활용 1)함수에서 객체를 리턴할 때 const convertExtension = function (fullFileName) { const fullFileNameArr = fullFileName.split('.') const filename = fullFil..
6-1. 소개 var birds = ['eagle', 'pigeon'] var mammals = ['rabbit', 'cat'] var animals = birds.concat('whale').concat(mammals) console.log(animals) const animals2 = [...birds, 'whale', ...mammals] console.log(animals2) 위 코드는 다음과 같은 결과를 나타낼 것이다. 이를 더 간단히 나타낼 수 있는 방법이 있다. var birds = ['eagle', 'pigeon'] var mammals = ['rabbit', 'cat'] var animals = birds.concat('whale').concat(mammals) const animals2..
6-1. 소개 var birds = ['eagle', 'pigeon'] var mammals = ['rabbit', 'cat'] var animals = birds.concat('whale').concat(mammals) console.log(animals) 위 코드는 다음과 같은 결과를 나타낼 것이다. 이를 더 간단히 나타낼 수 있는 방법이 있다. var birds = ['eagle', 'pigeon'] var mammals = ['rabbit', 'cat'] const animals2 = [...birds, 'whale', ...mammals] console.log(animals2) 결과는 같다. 6-2. 상세 1) 배열의 각 인자를 펼친 효과 const values = [20, 10, 30, 50,..
·JS
default parameter const f = function (x, y, z) { x = x ? x : 4 y = y || 5 if (!z) { z = 6 } console.log(x, y, z) } f(1) f(0, null) const f = function (x, y, z) { x = x !== undefined ? x : 3 y = typeof x !== "undefined" ? y : 4 console.log(x, y) } f(0, null) 위 코드를 해석하면 x에 undefined가 아니면 x를 할당하고 x가 undefined라면은 3을 할당하라, y는 x가 문자열 undefined가 아니면 y가 undefined라면은 4를 할당하라. const f = function (x, y, z)..
·JS
template literal template literal은 문자열이다. 문자열 선언하는 방식은 var a= 'abc' var b = "abc" var c = `abc` a === b b === c a === c string literal // 문자 그대로의 ``은 줄바꿈을 할때 공백을 그대로 출력하기 때문에 주의해야 한다. var a = 'abc\n' + 'def' console.log(a); // abc def var b = `a bb ccc`; console.log(b) // a bb ccc const a = 10 const b = 20 const strBefore = a + '+' + b + '=' + (a + b); const str = `${a} + ${b} = ${ a + b }`; con..
king_hd
웹 개발 기록