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

View File

@ -25,8 +25,9 @@
require( './common' );
var assert = require( 'assert' ),
Class = require( 'class' ),
abstractMethod = require( 'class' ).abstractMethod;
Class = require( '../lib/class' ),
abstractMethod = require( '../lib/class' ).abstractMethod,
util = require( '../lib/util' );
// not abstract
var Foo = Class.extend( {} );
@ -67,11 +68,18 @@ var ConcreteFoo = AbstractFoo.extend(
},
});
assert.ok(
( abstractMethod() instanceof 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()
{
abstractMethod()();