1
0
Fork 0

Abstract method list is now updated for classes that implement interfaces

closure/master
Mike Gerwitz 2011-01-03 23:25:27 -05:00
parent c12ac412cb
commit 0b112dac51
2 changed files with 37 additions and 5 deletions

View File

@ -49,8 +49,11 @@ exports.extend = function( base )
exports.implement = function()
{
var len = arguments.length,
dest = exports.extend(),
arg = null;
dest = {},
arg = null,
abstract_list = []
implemented = [];
// add each of the interfaces
for ( var i = 0; i < len; i++ )
@ -58,11 +61,20 @@ exports.implement = function()
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 );
util.propCopy( arg.prototype, dest );
implemented.push( arg );
}
return dest;
var class_new = exports.extend( dest );
// we cannot reassign the value since it is frozen, so copy the values into
// the array
while ( implemented[ 0 ] )
{
class_new.implemented.push( implemented.shift() );
}
return class_new;
};

View File

@ -70,3 +70,23 @@ assert.ok(
"Abstract methods are copied into the new class prototype"
);
assert.equal(
Foo.isAbstract(),
true,
"Classes that implements interface(s) are considered abstract if the " +
"implemented methods have no concrete implementations"
);
assert.equal(
Foo.abstractMethods.length,
2,
"Abstract methods list is updated when interface is implemented"
);
assert.ok(
( ( Foo.abstractMethods[ 0 ] == 'foo' )
&& ( Foo.abstractMethods[ 1 ] == 'foo2' )
),
"Abstract methods list contains names of implemented methods"
);