Added util.isAbstractMethod
parent
54432c78fa
commit
837422c46f
15
lib/util.js
15
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
|
||||
|
|
|
@ -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()();
|
||||
|
|
Loading…
Reference in New Issue