No need to recheck the type each time
parent
009c4a93e9
commit
7bb87e370f
33
lib/class.js
33
lib/class.js
|
@ -51,16 +51,19 @@ var class_meta = {};
|
|||
module.exports = function()
|
||||
{
|
||||
var def = {},
|
||||
name = '';
|
||||
name = '',
|
||||
type = typeof arguments[ 0 ]
|
||||
;
|
||||
|
||||
// anonymous class
|
||||
if ( typeof arguments[ 0 ] === 'object' )
|
||||
switch ( type )
|
||||
{
|
||||
// anonymous class
|
||||
case 'object':
|
||||
def = arguments[ 0 ];
|
||||
|
||||
// ensure we have the proper number of arguments (if they passed in too
|
||||
// many, it may signify that they don't know what they're doing, and likely
|
||||
// they're not getting the result they're looking for)
|
||||
// ensure we have the proper number of arguments (if they passed in
|
||||
// too many, it may signify that they don't know what they're doing,
|
||||
// and likely they're not getting the result they're looking for)
|
||||
if ( arguments.length > 1 )
|
||||
{
|
||||
throw Error(
|
||||
|
@ -68,10 +71,11 @@ module.exports = function()
|
|||
arguments.length + " given."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// named class
|
||||
else if ( typeof arguments[ 0 ] === 'string' )
|
||||
{
|
||||
case 'string':
|
||||
name = arguments[ 0 ];
|
||||
def = arguments[ 1 ];
|
||||
|
||||
|
@ -81,11 +85,14 @@ module.exports = function()
|
|||
// the definition must be an object
|
||||
if ( typeof def !== 'object' )
|
||||
{
|
||||
throw TypeError( "Unexpected value for named class definition" );
|
||||
throw TypeError(
|
||||
"Unexpected value for named class definition"
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// we don't know what to do!
|
||||
throw TypeError(
|
||||
"Expecting anonymous class definition or named class definition"
|
||||
|
|
|
@ -43,16 +43,19 @@ var util = require( './util' ),
|
|||
module.exports = function()
|
||||
{
|
||||
var def = {},
|
||||
name = '';
|
||||
name = '',
|
||||
type = typeof arguments[ 0 ]
|
||||
;
|
||||
|
||||
// anonymous interface
|
||||
if ( typeof arguments[ 0 ] === 'object' )
|
||||
switch ( type )
|
||||
{
|
||||
// anonymous interface
|
||||
case 'object':
|
||||
def = arguments[ 0 ];
|
||||
|
||||
// ensure we have the proper number of arguments (if they passed in too
|
||||
// many, it may signify that they don't know what they're doing, and likely
|
||||
// they're not getting the result they're looking for)
|
||||
// ensure we have the proper number of arguments (if they passed in
|
||||
// too many, it may signify that they don't know what they're doing,
|
||||
// and likely they're not getting the result they're looking for)
|
||||
if ( arguments.length > 1 )
|
||||
{
|
||||
throw Error(
|
||||
|
@ -60,21 +63,24 @@ module.exports = function()
|
|||
arguments.length + " given."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// named class
|
||||
else if ( typeof arguments[ 0 ] === 'string' )
|
||||
{
|
||||
case 'string':
|
||||
name = arguments[ 0 ];
|
||||
def = arguments[ 1 ];
|
||||
|
||||
// add the name to the definition
|
||||
def.__name = name;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// we don't know what to do!
|
||||
throw TypeError(
|
||||
"Expecting anonymous interface definition or named interface definition"
|
||||
"Expecting anonymous interface definition or named " +
|
||||
"interface definition"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue