1
0
Fork 0

Added abstract method support to propParse()

closure/master
Mike Gerwitz 2010-12-04 14:03:26 -05:00
parent 4037cc1343
commit 6fd31a8e76
2 changed files with 30 additions and 10 deletions

View File

@ -96,9 +96,10 @@ exports.defineSecureProp = function( obj, prop, value )
*/
exports.propParse = function( data, options )
{
var callback_prop = options.property || function() {},
callback_method = options.method || function() {},
callback = null;
var callback_prop = options.property || function() {},
callback_method = options.method || function() {},
callback_abstract_method = options.abstractMethod || function() {},
callback = null;
// for each of the given properties, determine what type of property we're
// dealing with (in the classic OO sense)
@ -108,7 +109,11 @@ exports.propParse = function( data, options )
if ( value instanceof Function )
{
callback = callback_method;
// concrete or abstract?
callback = ( exports.isAbstractMethod( value ) )
? callback_abstract_method
: callback_method
;
}
else
{

View File

@ -24,8 +24,8 @@
require( './common' );
var assert = require( 'assert' ),
propParse = require( '../lib/util' ).propParse;
var assert = require( 'assert' ),
util = require( '../lib/util' );
var data = {
// scalars (properties)
@ -42,13 +42,17 @@ var data = {
// concrete method
method: function() {},
// abstract method
abstractMethod: util.createAbstractMethod(),
};
var props = {},
methods = {};
var props = {},
methods = {},
amethods = {};
propParse( data, {
util.propParse( data, {
property: function( name, value )
{
props[ name ] = value;
@ -59,6 +63,11 @@ propParse( data, {
{
methods[ name ] = method;
},
abstractMethod: function( name, def )
{
amethods[ name ] = def;
}
} );
@ -76,6 +85,12 @@ propParse( data, {
assert.equal(
methods.method,
data.method,
"Property parser properly detects methods"
"Property parser properly detects concrete methods"
);
assert.equal(
amethods.abstractMethod,
data.abstractMethod,
"Property parser properly detects abstract methods"
);