From d5d6082bfb49f80e2bf847de6aa0a993d9aa8cf2 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 29 Dec 2010 23:34:12 -0500 Subject: [PATCH] Interface methods are now copied to the class prototype (basic implementation - no deep copy for interface subtypes yet) --- lib/class.js | 3 +++ test/test-class-implements.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/class.js b/lib/class.js index 10c19be..96672b6 100644 --- a/lib/class.js +++ b/lib/class.js @@ -56,6 +56,9 @@ exports.implements = function() for ( var i = 0; i < len; i++ ) { arg = arguments[ i ]; + + // copy all interface methods to the class (does not yet deep copy) + util.propCopy( arg.prototype, dest.prototype ); dest.implemented.push( arg ); } diff --git a/test/test-class-implements.js b/test/test-class-implements.js index 7599e22..9fd605b 100644 --- a/test/test-class-implements.js +++ b/test/test-class-implements.js @@ -63,3 +63,10 @@ assert.ok( "Class contains list of implemented interfaces" ); +assert.ok( + ( ( Foo.prototype.foo instanceof Function ) + && ( Foo.prototype.foo2 instanceof Function ) + ), + "Abstract methods are copied into the new class prototype" +); +