نسخة الكود كما يلي:
// استخدم انتحال شخصية الكائن لتحقيق ميراث JS
وظيفة (لون) {
this.acolor = اللون ؛
this.ashowcolor = function () {
document.writeln ("Acolor:" + this.acolor) ؛
}
}
الوظيفة B (اللون ، الاسم) {
// تعيين newmethod إلى A واتصل بمنشئ A
this.newmethod = a ؛
this.newmethod (color) ؛
// ثم حذف الإشارة إلى A ، بحيث لا يمكن استدعاؤه في المستقبل
حذف this.newmethod ؛
this.bname = name ؛
this.bshowname = function () {
document.writeln ("bname:" + this.bname) ؛
}
}
var obja = جديد ("أحمر") ؛
obja.ashowcolor () ؛
document.writeln ("------------------------------------------------------------------------------------------------------------------------
var objb = new B ("Black" ، "Demo") ؛
objb.ashowcolor () ؛
objb.bshowname () ؛
document.writeln ("------------------------------------------------------------------------------------------------------------------------