Abstract classes also have a more intuitive string representation
parent
d19638be4f
commit
afc5d4668d
10
lib/class.js
10
lib/class.js
|
@ -338,13 +338,21 @@ var extend = ( function( extending )
|
|||
// abstract class
|
||||
else
|
||||
{
|
||||
return function()
|
||||
var __abstract_self = function()
|
||||
{
|
||||
if ( !extending )
|
||||
{
|
||||
throw new Error( "Abstract classes cannot be instantiated" );
|
||||
}
|
||||
};
|
||||
|
||||
// provide a more intuitive string representation
|
||||
__abstract_self.toString = function()
|
||||
{
|
||||
return '<Abstract Class>';
|
||||
};
|
||||
|
||||
return __abstract_self;
|
||||
}
|
||||
}
|
||||
} )( false );
|
||||
|
|
|
@ -207,3 +207,15 @@ assert.throws( function()
|
|||
} );
|
||||
}, TypeError, "Abstract methods must be declared as arrays" );
|
||||
|
||||
|
||||
// otherwise it'll output the internal constructor code, which is especially
|
||||
// confusing since the user does not write it
|
||||
( function testConvertingAbstractClassToStringYieldsClassString()
|
||||
{
|
||||
assert.equal(
|
||||
Class.extend( { 'abstract foo': [] } ).toString(),
|
||||
'<Abstract Class>',
|
||||
"Converting abstract class to string yields class string"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
|
Loading…
Reference in New Issue