이 기사는 JavaScript에서 객체 지향 객체에 대한 심층적 인 이해를 추가로 분석하고 설명합니다. 참조를 위해 공유하십시오. 특정 분석은 다음과 같습니다.
JavaScript 객체 지향 프로그래밍에서 모든 것이 객체라는 것을 이해할 수 있습니다. 예제 코드는 다음과 같습니다.
다음과 같이 코드를 복사하십시오. <script language = "javaScript"type = "text/javaScript">
기능 cat () {
}
var cat1 = new cat (); // 클래스 인스턴스를 만듭니다
cat1.name = "강아지";
cat1.age = 4;
cat1.color = "흰색";
document.write (cat1.name);
document.writeln (cat1.constructor); // 인스턴스화 후 객체는 객체입니다
document.writeln (typeof (cat1)+"<hr />");
document.writeln (cat.constructor); // 프로토 타입 객체 자체도 객체입니다
document.writeln (typeof cat+"<hr />");
var b = "hello"; // 스탠드도 물체입니다
document.writeln (b.constructor); // 생성자를 출력합니다
document.writeln (typeof b+"<hr />");
var c = 123; // 값도 객체입니다
Document.writeln (C.constructor);
document.writeln (typeof c+"<hr />");
</스크립트>
인스턴스화 된 객체가 특정 프로토 타입 객체 유형인지 확인
코드 사본은 다음과 같습니다. if (cat1 instanceof cat) {// php와 동일한 방법
window.alert ( "OK");
}
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.