การคัดลอกรหัสมีดังนี้:
// ใช้การแอบอ้างวัตถุเพื่อตระหนักถึงการสืบทอด JS
ฟังก์ชั่น A (สี) {
this.acolor = color;
this.ashowColor = function () {
document.writeln ("Acolor:" + this.acolor);
-
-
ฟังก์ชั่น B (สีชื่อ) {
// กำหนด newMethod ให้กับ A และ Call A Constructor
this.newMethod = a;
this.newmethod (สี);
// จากนั้นลบการอ้างอิงไปยัง A เพื่อที่เขาจะไม่สามารถเรียกได้ในอนาคต
ลบสิ่งนี้ใหม่
this.bname = ชื่อ;
this.bshowname = function () {
document.writeln ("bname:" + this.bname);
-
-
var obja = ใหม่ a ("สีแดง");
obja.ashowcolor ();
Document.writeLn ("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var objb = new b ("ดำ", "สาธิต");
objb.ashowcolor ();
objb.bshowname ();
Document.writeLn ("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------