abstractMethod() moved to util.defineAbstractMethod
parent
b3c4b757e7
commit
54432c78fa
26
lib/class.js
26
lib/class.js
|
@ -39,31 +39,7 @@ exports.extend = function( base )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
exports.abstractMethod = util.createAbstractMethod;
|
||||||
* Creates an abstract method
|
|
||||||
*
|
|
||||||
* Abstract methods must be implemented by a subclass and cannot be called
|
|
||||||
* directly. If a class contains a single abstract method, the class itself is
|
|
||||||
* considered to be abstract and cannot be instantiated. It may only be
|
|
||||||
* extended.
|
|
||||||
*
|
|
||||||
* @param {Function} definition function definition that concrete
|
|
||||||
* implementations must follow
|
|
||||||
*
|
|
||||||
* @return {Function}
|
|
||||||
*/
|
|
||||||
exports.abstractMethod = function( definition )
|
|
||||||
{
|
|
||||||
var method = function()
|
|
||||||
{
|
|
||||||
throw new Error( "Cannot call abstract method" );
|
|
||||||
};
|
|
||||||
|
|
||||||
util.defineSecureProp( method, 'abstractFlag', true );
|
|
||||||
util.defineSecureProp( method, 'definition', definition );
|
|
||||||
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
28
lib/util.js
28
lib/util.js
|
@ -186,6 +186,34 @@ exports.propCopy = function( props, dest, result_data )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an abstract method
|
||||||
|
*
|
||||||
|
* Abstract methods must be implemented by a subclass and cannot be called
|
||||||
|
* directly. If a class contains a single abstract method, the class itself is
|
||||||
|
* considered to be abstract and cannot be instantiated. It may only be
|
||||||
|
* extended.
|
||||||
|
*
|
||||||
|
* @param {Function} definition function definition that concrete
|
||||||
|
* implementations must follow
|
||||||
|
*
|
||||||
|
* @return {Function}
|
||||||
|
*/
|
||||||
|
exports.createAbstractMethod = function( definition )
|
||||||
|
{
|
||||||
|
var method = function()
|
||||||
|
{
|
||||||
|
throw new Error( "Cannot call abstract method" );
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.defineSecureProp( method, 'abstractFlag', true );
|
||||||
|
exports.defineSecureProp( method, 'definition', definition );
|
||||||
|
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides a method
|
* Overrides a method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue