-
자바 스크립트프로그래밍 언어/클래스 2012. 8. 13. 14:44
null
var obj = new Object();
or var obj = new Object;
or var obj = {};
obj.name = "Simon"
var name = obj.name;
obj["name"] = "Simon";
var name = obj["name"];
obj["for"] = "Simon";
var obj = {
name: "Carrot",
"for": "Max",
details: {
color: "orange",
size: 12
}
}
> obj.details.color
orange
> obj["details"]["size"]
12
.prototype
인스턴스된 모든 객체에서 공유할 수 있는 객체
function personFullName() {
return this.first + ' ' + this.last;
}
function personFullNameReversed() {
return this.last + ', ' + this.first;
}
function Person(first, last) {
this.first = first;
this.last = last;
this.fullName = personFullName;
this.fullNameReversed = personFullNameReversed;
}
function Person(first, last) {
this.first = first;
this.last = last;
}
Person.prototype.fullName = function() {
return this.first + ' ' + this.last;
}
Person.prototype.fullNameReversed = function() {
return this.last + ', ' + this.first;
}
Object.prototype
.toString()
> var a = new Array();
> a[0] = "dog";
> a[1] = "cat";
> a[2] = "hen";
> var a = ["dog", "cat", "hen"];