2011-05-22 11:11:18 -04:00
|
|
|
/**
|
|
|
|
* Wrapper permitting the definition of final classes
|
|
|
|
*
|
2013-12-22 08:53:10 -05:00
|
|
|
* Copyright (C) 2010, 2011, 2013 Mike Gerwitz
|
2011-05-22 11:11:18 -04:00
|
|
|
*
|
2013-12-22 09:37:21 -05:00
|
|
|
* This file is part of GNU ease.js.
|
2011-05-22 11:11:18 -04:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* ease.js is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-05-22 11:11:18 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
var Class = require( __dirname + '/class' );
|
|
|
|
|
2011-05-22 21:35:29 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a final class
|
|
|
|
*
|
2011-12-13 21:19:14 -05:00
|
|
|
* @return {Function} final class
|
2011-05-22 21:35:29 -04:00
|
|
|
*/
|
|
|
|
exports = module.exports = function()
|
|
|
|
{
|
|
|
|
markFinal( arguments );
|
|
|
|
|
|
|
|
// forward everything to Class
|
|
|
|
var result = Class.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( !Class.isClass( result ) )
|
|
|
|
{
|
|
|
|
finalOverride( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a final class from a class extend operation
|
|
|
|
*
|
2011-12-13 21:19:14 -05:00
|
|
|
* @return {Function} final class
|
2011-05-22 21:35:29 -04:00
|
|
|
*/
|
|
|
|
exports.extend = function()
|
|
|
|
{
|
|
|
|
markFinal( arguments );
|
|
|
|
return Class.extend.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes a definition to be flagged as final
|
|
|
|
*
|
|
|
|
* This function assumes the last argument to be the definition, which is the
|
|
|
|
* common case, and modifies the object referenced by that argument.
|
|
|
|
*
|
2011-12-13 21:19:14 -05:00
|
|
|
* @param {!Arguments} args arguments to parse
|
2011-05-22 21:35:29 -04:00
|
|
|
*
|
|
|
|
* @return {undefined}
|
|
|
|
*/
|
|
|
|
function markFinal( args )
|
2011-05-22 11:11:18 -04:00
|
|
|
{
|
|
|
|
// the last argument _should_ be the definition
|
2011-05-22 21:35:29 -04:00
|
|
|
var dfn = args[ args.length - 1 ];
|
2011-05-22 11:11:18 -04:00
|
|
|
|
|
|
|
if ( typeof dfn === 'object' )
|
|
|
|
{
|
2011-05-22 21:35:29 -04:00
|
|
|
// mark as abstract
|
2011-05-22 11:11:18 -04:00
|
|
|
dfn.___$$final$$ = true;
|
|
|
|
}
|
2011-05-22 21:35:29 -04:00
|
|
|
}
|
2011-05-22 11:11:18 -04:00
|
|
|
|
2011-05-22 21:35:29 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides object members to permit final classes
|
|
|
|
*
|
|
|
|
* @param {Object} obj object to override
|
|
|
|
*
|
|
|
|
* @return {undefined}
|
|
|
|
*/
|
|
|
|
function finalOverride( obj )
|
|
|
|
{
|
|
|
|
var extend = obj.extend;
|
|
|
|
|
|
|
|
// wrap extend, applying the abstract flag
|
|
|
|
obj.extend = function()
|
|
|
|
{
|
|
|
|
markFinal( arguments );
|
|
|
|
return extend.apply( this, arguments );
|
|
|
|
};
|
|
|
|
}
|
2011-05-22 11:11:18 -04:00
|
|
|
|