class Product {
constructor(name, price) {
this.name = name;
this.price = price;
}
print() {
console.log(`${this.name}의 가격은 ${this.price}원입니다.`);
}
}
let products = [
new Product('ㅐㅐㅐ"',20151020),
new Product('사과',2000),
new Product('배',3000),
new Product('고구마',700),
new Product('감자',600),
new Product('수박',500),
];
for(let product of products) {
product.print();
}
class 는 그림자 분신술
constructor는 분신술 시전자
this는 분신1 ,분신2, 분신3.... 복사되어지는 인스턴스 객체를 의미
매개 변수에 따라 담아와진 정보들은 시전자가 반영하여(this.name = name) 분신을 잘 생성해준다.
(물론 저 안에 시전자 본인은 없다)
위가 과거 밑이 현재최신버전
var sayNode = function () {
console.log('Node');
};
var es = 'ES';
var oldObject = {
sayJS: function() {
console.log('JS');
},
sayNode : sayNode,
};
oldObject[es + 6] ='Fantastic';
oldObject.sayNode();
oldObject.sayJS();
console.log(oldObject.ES6);
console.log('------------------');
const newObject = {
sayJS() {
console.log('JS');
},
sayNode,
[es + 6]: 'Fantastic',
};
newObject.sayNode();
newObject.sayJS();
console.log(newObject.ES6);
'🗃️javascript > 이론정리' 카테고리의 다른 글
arguments (매개변수를 다루는 유사 배열 객체) (0) | 2023.10.07 |
---|---|
기본 자료형, 객체 자료형 (0) | 2023.09.25 |
js 개발 이론정리(2)[문자열 잇기] (0) | 2023.04.03 |
js 개발 이론정리(1)[async, defer, 데이터 타입] (0) | 2023.04.02 |
js 기본 정리 시작 이유 + js 환경 조성 (0) | 2023.04.02 |