const megalomaniac = {
mastermind: 'Brain',
henchman: 'Pinky',
getFusion: function () {
return henchman + mastermind; //henchman is not defined
return this.henchman + this.mastermind //이래야 가져올수있음
},
battleCry(numOfBrains) {
return `They are ${this.henchman} and the` + ` ${this.mastermind}`.repeat(numOfBrains);
},
};
const subtractor = x => y => { //변수처럼 함수이름 먼저 써주자
return x - y
}
let overTwenty = true;
let allowedToDrink = overTwenty; //allowedToDrink = true
overTwenty = false;
allowedToDrink // true임, 값을 복사한거지 주소값 복사한게 아님
[1,2,3] === [1,2,3] // false
'name' in job //true
delete job.jame
const megalomaniac = {
mastermind: 'Brain',
henchman: 'Pinky',
getFusion: function () {
return this.henchman + this.mastermind;
},
function makePizza(dough, name, ...toppings) {
const order = `You ordered ${name} pizza with ${dough} dough and ${toppings.length} extra toppings!`;
return order;
}
expect(makePizza('napoli', 'meat', 'extra cheese', 'onion', 'bacon')).to.equal(`You ordered meat pizza with napoli dough and 3 extra toppings!`); // 세번째 매개변수부터 ...toppings의 배열로 들어가게됨.
function getAllParams(required1, required2, ...args) {
return [required1, required2, args];
}
expect(getAllParams(123)).to.deep.equal([123,undefined,[]]); //[1,2,3]아님
const array = ['code', 'states', 'im', 'course']
const [start, ...rest] = array // rest? spread?
expect(start).to.eql('code')
expect(rest).to.eql(['states','im','course']) //'states','im','course'아님 rest라 배열임
const name = '김코딩'
const age = 28
const person = {
name, //this.name 안됨.
age,
level: 'Junior',
}
expect(person).to.eql({name : '김코딩',age : 28,level:'Junior'})
const student = { name: '박해커', major: '물리학과' }
const { name } = student
expect(name).to.eql('박해커')
const student = { name: '최초보', major: '물리학과' }
const { name, ...args } = student
expect(name).to.eql('최초보')
expect(args).to.eql({major: '물리학과'})//'물리학과'아님
const student = { name: '최초보', major: '물리학과', lesson: '양자역학', grade: 'B+' }
function getSummary({ name, lesson: course, grade }) {
return `${name}님은 ${grade}의 성적으로 ${course}을 수강했습니다`
}//그냥 키값만 적어두면 키변수가 값이 되고, 키: 값꼴로 적어두면 값부분을 쓰면된다.
expect(getSummary(student)).to.eql(`최초보님은 B+의 성적으로 양자역학을 수강했습니다`)
10번에 '객체의 단축(shorthand) 문법을 익힙니다'에서 객체 person이 name : this.name으로 못받는건 왤까요?