diff --git a/lib/class.js b/lib/class.js index a4b293b..960a003 100644 --- a/lib/class.js +++ b/lib/class.js @@ -361,6 +361,15 @@ function createImplement( base, ifaces, cname ) ext_base = args.pop() ; + // if any arguments remain, then they likely misunderstood what this + // method does + if ( args.length > 0 ) + { + throw Error( + "Expecting no more than two arguments for extend()" + ); + } + // if a base was already provided for extending, don't allow them to // give us yet another one (doesn't make sense) if ( base && ext_base ) diff --git a/test/test-class-implement.js b/test/test-class-implement.js index 0bdad6e..4e6e15d 100644 --- a/test/test-class-implement.js +++ b/test/test-class-implement.js @@ -232,3 +232,16 @@ var Type = Interface.extend( { ); } )(); + +/** + * If more than two arguments are given to extend(), then the developer likely + * does not understand the API. Throw an error to prevent some bugs/confusion. + */ +( function testThrowsExceptionIfExtendContainsTooManyArguments() +{ + assert.throws( function() + { + Class.implement( Type ).extend( PlainFoo, {}, 'extra' ); + }, Error, "extend() after implementing accepts no more than two args" ); +} )(); +