diff --git a/lib/util.js b/lib/util.js index a438f08..301e4a6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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 diff --git a/test/test-class-abstract.js b/test/test-class-abstract.js index 7885bc0..1785318 100644 --- a/test/test-class-abstract.js +++ b/test/test-class-abstract.js @@ -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()();