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

View File

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