멋쟁이 사자처럼_1206

jojo·2021년 12월 6일
1

멋쟁이사자처럼

목록 보기
30/39
post-thumbnail

수업

매서드체이닝

반환되는 객체를 이용해 또 다른 함수를 호출한다.

let sum = 0;
'123456'.split('').map(value => parseInt(value)).forEach(value => sum += value)

sum
-> 21


'123456'.split('')

하나씩 잘린다.

-> ['1', '2', '3', '4', '5', '6']


'123456'.split('').map(value => parseInt(value))

밸류 값이 들어오면 숫자로 변환시켜주겠다.


.forEach(value => sum += value)

하나씩 순회하는데, 얘를 숫자를 하나씩 더하면서 누적해주겠다ㅏ.

Math

ceil
올림. 음수에서의 올림이 헷갈릴 수 있으니 주의해야 한다.
-9.2는 올림하면 -9이다.

Math.ceil(9.2)
-> 10

Math.ceil(-9.2)
-> -9


floor
내림. 음수에서의 내림 주의.

Math.floor(0.3)
-> 0

Math.floor(-9.2)
-> -10


round
반올림.

Math.round(3.6)
-> 4

Math.round(3.2)
-> 3


Math.max()
-> -Infinity

Math.min()
-> Infinity

Math.max(1, 2, 3, 0.1)
-> 3

Math.min(1, 2, 3, 0.1)
-> 0.1


Math.max([1, 2, 10, 6, 7])
-> NaN

Math.max(...[1, 2, 10, 6, 7])
-> 10


reduce: 잘 안쓰지만 옛날에 써서..보게될수도 있다.

https://ko.javascript.info/array-methods

모던자바스크립트 예제

let arr = [1, 2, 3, 4, 5];
let result = arr.reduce((sum, current) => sum + current);

console.log(result)
->15

대체:

let s = 0;
arr.forEach( i => s += i)

s
-> 15

Number

Number.EPSILON
-> 2.220446049250313e-16

자바스크립트에서 언제든지 날 수 있는 연산의 오차


Number.MAX_SAFE_INTEGER
Number.MIN_SAFE_INTEGER

연산자가 제대로 돌아가는 마지노선이다.(이 값을 넘어가는 값은 받지 않겠다)


this

this - mozilla 참고링크:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

자신을 호출한 객체
자신이 생성할 객체


function sayName(){

console.log(this.name);

}


var name = 'Hero';

전역으로 선언한 name 변수의 앞에는 window 가 생략되어 있다.
따라서 var name은 여기에서는 window.name이고, window.name === "Hero" 가 성립한다.

let peter = {
name : 'Peter Parker',
sayName : sayName
}

let bruce = {
name : 'Bruce Wayne',
sayName : sayName
}

sayName();
peter.sayName();
bruce.sayName();

sayName을 호출한 것의 name


let 호텔 = [{
'이름' : '하나호텔',
'위치' : '제주도 제주시 001',
'가격' : {'A':50000, 'B':30000, 'C':15000},
'방의개수' : 50,
'예약자수' : 25,
'남은방의개수' : function(){return this.방의개수 - this.예약자수}
},{
'이름' : '둘호텔',
'위치' : '제주도 제주시 002',
'가격' : {'A':100000, 'B':60000, 'C':30000},
'방의개수' : 100,
'예약자수' : 30,
'남은방의개수' : function(){return this.방의개수 - this.예약자수}
},{
'이름' : '셋호텔',
'위치' : '제주도 제주시 003',
'가격' : {'A':80000, 'B':50000, 'C':30000},
'방의개수' : 120,
'예약자수' : 80,
'남은방의개수' : function(){return this.방의개수 - this.예약자수}
}];

console.log(호텔[0].남은방의개수());
console.log(호텔[1].남은방의개수());
console.log(호텔[2].남은방의개수());



-> 25 70 40


this 사용자 값을 의도대로 조작

call
this를 대체할 수 있다.

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/call

apply
this를 대체할 수 있다.

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/apply

bind
호출을 하지 않는다.

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/bind



json

https://ko.javascript.info/json


let student = {
    name: 'John',
    age: 30,
    isAdmin: false,
    courses: ['html', 'css', 'js'],
    wife: null
};




let user = {
    name: "John",
    age: 25,
    roles: {
        isAdmin: false,
        isEditor: true
    }
};


console.log(JSON.stringify(user, null, 4))


생각

후... 자바스크립트 지난주도 너무 어렵고 실습시간에도 나 혼자 못하고 머리 싸매고 있는 기분이다. 얘기들어보면 나만 그런 것 같지는 않지만, 그래도 정말.. 다들 달려가는데 혼자서 기어가는 것 같다. 조급해하면 안되는데


느낀점

고칠점

  • 건강 안 챙긴 것.. 주말에 푹 쉬고 월요일 컨디션이 좋아야 하는데, 항상 그게 어렵다. 이제 두달도 안 남았는데 집중하자!

계획

  • 몸 챙기기(운동 주 3회 이상 꼭 하기)
  • 괜히 집중 안 될 때 질질 끌지 말고 짧은 시간동안 몰입해서 빠르게 끝내기
profile
2021.11~

0개의 댓글