코드 사본은 다음과 같습니다.
// js 상속을 실현하기 위해 객체 가장합니다
기능 a (색) {
this.acolor = 색상;
this.ashowcolor = function () {
document.writeln ( "acolor :" + this.acolor);
}
}
함수 B (색상, 이름) {
// newMethod를 A에 할당하고 A의 생성자를 호출합니다
this.newmethod = a;
this.newmethod (색);
// 그런 다음 A에 대한 참조를 삭제하여 미래에 호출 할 수 없습니다.
this.newmethod;
this.bname = 이름;
this.bshowname = function () {
document.writeln ( "bname :" + this.bname);
}
}
var obja = new a ( "빨간색");
obja.ashowcolor ();
document.writeln("------------------------------------------------------------------------------------------------------------------------
var objb = new B ( "검은 색", "데모");
objb.ashowcolor ();
objb.bshowname ();
document.writeln("------------------------------------------------------------------------------------------------------------------------