Chapter7-1. 객체
객체의 개념
JS 객체
var normal = '하' // 일반 변수
var obj = { first_name: 'sang', last_name: 'nam', age: 27 }; // 객체var normal = '하' // 일반 변수
var obj = { first_name: 'sang', last_name: 'nam', age: 27 }; // 객체var test = {
test1: "asd",
test2: "zxcv"
};function Test(name, age) {
this.name = name;
this.age = age;
}
a = new Test("ha", 1);a.func = function() {
console.log("new method");
}
a.func() // new method
b = Test("b", 100)
b.func() // errorTest.prototype.func() = function() {
console.log("This is new method!");
}
b = new Test("b", 10);
b.func() // This is new methodvar a = new Test("a", 10);
var b = new Test("a", 10);
a == b // false
a === b // false
var c = a;
a == c // true
a === c //true