
첫 κΈμλ λ³΄ν΅ λλ¬Έμλ‘!
λΉμ·ν κ°μ²΄λ₯Ό μ¬λ¬ κ° λ§λ€ λ μ¬μ©
λΆμ΄λΉ΅, μν νμ΄λΌκ³ μκ°ν΄λ³΄κΈ°~~function User(name, age) { this.name = name; this.age = age; } let user1 = new User('Mike', 30); let user2 = new User('Jane', 18); //new μ°μ°μλ₯Ό μ¬μ©ν΄μ νΈμΆ
function User(name, age) {
//this = {}
this.name = name;
this.age = age;
//return this;
}
new ν¨μλͺ
();
function User(name, age) { this.name = name; this.age = age; **this.sayName = function(){ console.log(this.name); } ** } let user3= new User('Han', 65) user3.sayName(); //'Han'
//μμ±μ ν¨μ: μν κ°μ²΄λ₯Ό μμ±ν΄λ³΄μ.
function Item(title, price){
//this = {};
this.title=title;
this.price=price;
this.showPrice = function(){
console.log(`κ°κ²©μ ${price}μ μ
λλ€.`);
};
//return this;
}
const item1 = new Item("μΈν", 3000);
const item2 = new Item("κ°λ°©", 40000);
console.log(item1) //Item {title:"μΈν", price:3000, showPrice:f}
item2.showPrice(); //κ°κ²©μ 40000μ μ
λλ€.