diff --git a/lib/class.js b/lib/class.js index 5f7b947..7ef56f6 100644 --- a/lib/class.js +++ b/lib/class.js @@ -51,45 +51,52 @@ var class_meta = {}; module.exports = function() { var def = {}, - name = ''; + name = '', + type = typeof arguments[ 0 ] + ; - // anonymous class - if ( typeof arguments[ 0 ] === 'object' ) + switch ( type ) { - def = arguments[ 0 ]; + // 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) - if ( arguments.length > 1 ) - { - throw Error( - "Expecting one argument for Class definition; " + - arguments.length + " given." + // 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( + "Expecting one argument for Class definition; " + + arguments.length + " given." + ); + } + + break; + + // named class + case 'string': + name = arguments[ 0 ]; + def = arguments[ 1 ]; + + // add the name to the definition + def.__name = name; + + // the definition must be an object + if ( typeof def !== 'object' ) + { + throw TypeError( + "Unexpected value for named class definition" + ); + } + + break; + + default: + // we don't know what to do! + throw TypeError( + "Expecting anonymous class definition or named class definition" ); - } - } - // named class - else if ( typeof arguments[ 0 ] === 'string' ) - { - name = arguments[ 0 ]; - def = arguments[ 1 ]; - - // add the name to the definition - def.__name = name; - - // the definition must be an object - if ( typeof def !== 'object' ) - { - throw TypeError( "Unexpected value for named class definition" ); - } - } - else - { - // we don't know what to do! - throw TypeError( - "Expecting anonymous class definition or named class definition" - ); } return extend( def ); diff --git a/lib/interface.js b/lib/interface.js index 6e41e8d..1ae2ce3 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -43,39 +43,45 @@ var util = require( './util' ), module.exports = function() { var def = {}, - name = ''; + name = '', + type = typeof arguments[ 0 ] + ; - // anonymous interface - if ( typeof arguments[ 0 ] === 'object' ) + switch ( type ) { - def = arguments[ 0 ]; + // 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) - if ( arguments.length > 1 ) - { - throw Error( - "Expecting one argument for Interface definition; " + - arguments.length + " given." + // 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( + "Expecting one argument for Interface definition; " + + arguments.length + " given." + ); + } + + break; + + // named class + case 'string': + name = arguments[ 0 ]; + def = arguments[ 1 ]; + + // add the name to the definition + def.__name = name; + + break; + + default: + // we don't know what to do! + throw TypeError( + "Expecting anonymous interface definition or named " + + "interface definition" ); - } - } - // named class - else if ( typeof arguments[ 0 ] === 'string' ) - { - name = arguments[ 0 ]; - def = arguments[ 1 ]; - - // add the name to the definition - def.__name = name; - } - else - { - // we don't know what to do! - throw TypeError( - "Expecting anonymous interface definition or named interface definition" - ); } return extend( def );