코드 사본은 다음과 같습니다.
// 호출 방법을 사용하여 JS 상속을 구현합니다
기능 a (색) {
this.acolor = 색상;
this.ashowcolor = function () {
document.writeln ( "acolor :" + this.acolor);
}
}
함수 B (색상, 이름) {
A.call (this, color);
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("------------------------------------------------------------------------------------------------------------------------