티스토리 뷰


constructor 속성은 객체를 만드는 기능함수를 반환하거나, 설정을 하는 메소드 이다.
 생성된 객체의 constructor 속성을 통해 해당 생성자 함수와 일치 여부가 가능하다

function A() {
	this.name = "A함수";
	this.getName = function() {
		return this.name;
	}
}

a = new A();

document.writeln(a.constructor);

//function A() { this.name = "A\uD568\uC218"; this.getName = function () {return this.name;}; } 

document.writeln(a.constructor == A);   //결과 : true

function A() {
	this.name;
	this.setName = function(name) {
		this.name = name;
	}
	this.getName = function() {
		return this.name;
	}
}

a = new A();
a.setName("a함수");
b = new A();
b.setName("b함수");

document.writeln(a.getName());	//결과 "a함수"
document.writeln(b.getName());	//결과 "b함수"

document.writeln(a.constructor == b.constructor);	//결과 : true


두 객체가 각자 다른 값과 역활을 가지고 있어도 생성자 함수가 동일한지 체크 할수 있다.

'웹개발 > Javascript' 카테고리의 다른 글

환율 API 정보 리스트  (0) 2012.03.12
자바스크립트 키코드.  (0) 2012.03.09
트위터 부트스트랩 자바스크립트 패턴  (0) 2012.03.09
Twitter jQuery  (0) 2012.03.05
천단위 콤마 찍기  (0) 2012.02.14
댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함