1
0
Fork 0

Now throwing expection if more than two arguments are passed to extend() when implementing

closure/master
Mike Gerwitz 2011-03-16 19:50:47 -04:00
parent 14cac6b461
commit 36ae6bcd81
2 changed files with 22 additions and 0 deletions

View File

@ -361,6 +361,15 @@ function createImplement( base, ifaces, cname )
ext_base = args.pop() 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 // if a base was already provided for extending, don't allow them to
// give us yet another one (doesn't make sense) // give us yet another one (doesn't make sense)
if ( base && ext_base ) if ( base && ext_base )

View File

@ -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" );
} )();