Intermediate 뜻은 1. 중간의, 2.중간물, 3.중개하다 4.중재하다 5.중급 ... 이런 뜻이 있다
중개하는 함수임을 알수 있다.
생성자 함수는
1.첫 글짜는 대문자로 이름을 짓는다
2. new 연산자를 사용해서 함수를 호출한다.
생성자 함수의 모델식
함수명 첫글자는 대문자로
function User(name,age) {
this.name=name;
this.age=age;
}
new 함수명( );
//메소드를 적용한 방법
function User(name,age) {
this.name=name;
this.age=age;
this.sayName=function( ){
console.log(this.name);
}
let user5 = new User('Han',40);
user5.sayName( );
//예제 : 상품객체 생성하라
function Item(title, price) {
this.title=title;
this.price=price;
this.showPrice=function(){
console.log('가격은 ${price}원 입니다');
};
}
const item1=new Item("모여라, 동물의숲", 300);
const item2=new Item("황혼의 숨결", 500);
const item3=new Item("피카츄", 1200);
console.log(item1,item2, item3);
item3.showPrice();
'JavsScript' 카테고리의 다른 글
Object.assign]객체 복제 (0) | 2022.02.13 |
---|---|
Computed property]계산된 프라퍼티 (0) | 2022.02.13 |
array (0) | 2022.02.13 |
객체 for ... in (0) | 2022.02.11 |
객체 2 (0) | 2022.02.11 |