1
0
Fork 0

Added util.isAbstractMethod

closure/master
Mike Gerwitz 2010-12-01 21:00:15 -05:00
parent 54432c78fa
commit 837422c46f
2 changed files with 25 additions and 2 deletions

View File

@ -213,6 +213,21 @@ exports.createAbstractMethod = function( definition )
} }
/**
* Determines if the given function is an abstract method
*
* @param {Function} function function to inspect
*
* @return {boolean} true if function is an abstract method, otherwise false
*/
exports.isAbstractMethod = function( func )
{
return ( ( func instanceof Function ) && ( func.abstractFlag === true ) )
? true
: false
;
}
/** /**
* Overrides a method * Overrides a method

View File

@ -25,8 +25,9 @@
require( './common' ); require( './common' );
var assert = require( 'assert' ), var assert = require( 'assert' ),
Class = require( 'class' ), Class = require( '../lib/class' ),
abstractMethod = require( 'class' ).abstractMethod; abstractMethod = require( '../lib/class' ).abstractMethod,
util = require( '../lib/util' );
// not abstract // not abstract
var Foo = Class.extend( {} ); var Foo = Class.extend( {} );
@ -67,11 +68,18 @@ var ConcreteFoo = AbstractFoo.extend(
}, },
}); });
assert.ok( assert.ok(
( abstractMethod() instanceof Function ), ( abstractMethod() instanceof Function ),
"abstractMethod() returns a function" "abstractMethod() returns a function"
); );
assert.ok(
( util.isAbstractMethod( abstractMethod() ) ),
"Functions returned by abstractMethod() are considered to be abstract by " +
"util.isAbstractMethod"
);
assert.throws( function() assert.throws( function()
{ {
abstractMethod()(); abstractMethod()();