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
|
* Overrides a method
|
||||||
|
|
|
@ -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()();
|
||||||
|
|
Loading…
Reference in New Issue