From d19638be4fb8d7ff96753f4fc7a13086e04028a8 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 17 Jan 2011 20:20:39 -0500 Subject: [PATCH] Classes now return a more intuitive string representation --- lib/class.js | 6 ++++++ test/test-class-extend.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/class.js b/lib/class.js index 75075c9..a5ee68e 100644 --- a/lib/class.js +++ b/lib/class.js @@ -327,6 +327,12 @@ var extend = ( function( extending ) attachInstanceOf( this ); }; + // provide a more intuitive string representation + __self.toString = function() + { + return ''; + }; + return __self; } // abstract class diff --git a/test/test-class-extend.js b/test/test-class-extend.js index 3061147..31c9e67 100644 --- a/test/test-class-extend.js +++ b/test/test-class-extend.js @@ -224,3 +224,15 @@ assert.ok( "Instances of subtypes do not share property references" ); + +// otherwise it'll output the internal constructor code, which is especially +// confusing since the user does not write it +( function testConvertingClassToStringYieldsClassString() +{ + assert.equal( + Class.extend( {} ).toString(), + '', + "Converting class to string yields class string" + ); +} )(); +