1
0
Fork 0

Both concrete and abstract methods now use the same callback in propParse()

- Now uses an is_abstract parameter
- Intended to reduce clutter and duplicate code
closure/master
Mike Gerwitz 2010-12-07 00:46:50 -05:00
parent 52b1ef657f
commit eced0a7e91
2 changed files with 21 additions and 47 deletions

View File

@ -96,14 +96,12 @@ exports.defineSecureProp = function( obj, prop, value )
*/
exports.propParse = function( data, options )
{
var fvoid = function() {},
callback_each = options.each || undefined,
callback_prop = options.property || fvoid,
callback_method = options.method || fvoid,
callback_abstract_method = options.abstractMethod || fvoid,
callback_getter = options.getter || fvoid,
callback_setter = options.setter || fvoid,
callback = null;
var fvoid = function() {},
callback_each = options.each || undefined,
callback_prop = options.property || fvoid,
callback_method = options.method || fvoid,
callback_getter = options.getter || fvoid,
callback_setter = options.setter || fvoid;
// for each of the given properties, determine what type of property we're
// dealing with (in the classic OO sense)
@ -131,20 +129,17 @@ exports.propParse = function( data, options )
// method
else if ( value instanceof Function )
{
// concrete or abstract?
callback = ( exports.isAbstractMethod( value ) )
? callback_abstract_method
: callback_method
;
callback_method(
prop,
value,
exports.isAbstractMethod( value )
);
}
// simple property
else
{
callback = callback_prop;
callback_prop( prop, value );
}
// call the appropriate callback
callback( prop, value );
}
}
@ -232,28 +227,7 @@ exports.propCopy = function( props, dest, result_data )
dest.__defineSetter__( name, func );
},
abstractMethod: function( name, def )
{
var data = { abstractModified: false },
pre = dest[ name ];
// check for override
if ( pre !== undefined )
{
dest[ name ] = attempt_override( name, pre, def, data );
if ( data.abstractModified )
{
abstract_regen = true;
}
}
else
{
abstract_methods.push( name );
dest[ name ] = def;
}
},
method: function( name, func )
method: function( name, func, is_abstract )
{
var data = { abstractModified: false },
pre = dest[ name ];
@ -271,6 +245,11 @@ exports.propCopy = function( props, dest, result_data )
{
// simply copy over the method
dest[ name ] = func;
if ( is_abstract )
{
abstract_methods.push( name );
}
}
},
};

View File

@ -80,15 +80,10 @@ util.propParse( data, {
props[ name ] = value;
},
// concrete method
method: function( name, method )
method: function( name, method, is_abstract )
{
methods[ name ] = method;
},
abstractMethod: function( name, def )
{
amethods[ name ] = def;
var to = ( is_abstract ) ? amethods : methods;
to[ name ] = method;
},
getter: function( name, func )