diff --git a/lib/class.js b/lib/class.js index a5ee68e..78dbf74 100644 --- a/lib/class.js +++ b/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 ''; + }; + + return __abstract_self; } } } )( false ); diff --git a/test/test-class-abstract.js b/test/test-class-abstract.js index 9f9e28f..cbf3a1d 100644 --- a/test/test-class-abstract.js +++ b/test/test-class-abstract.js @@ -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(), + '', + "Converting abstract class to string yields class string" + ); +} )(); +