1
0
Fork 0

Refactored defineProperty() code into define_secure_prop() function to reduce duplicate code

closure/master
Mike Gerwitz 2010-11-14 01:37:12 -05:00
parent d5b4477109
commit ad4b317955
1 changed files with 34 additions and 30 deletions

View File

@ -226,6 +226,38 @@ function setup_props( func, class_data )
}
/**
* Attempts to define a non-enumerable, non-writable and non-configurable
* property on the given object
*
* If the operation is unsupported, a normal property will be set.
*
* @param {Object} obj object to set property on
* @param {string} prop name of property to set
* @param {mixed} value value to set
*
* @return {undefined}
*/
function define_secure_prop( obj, prop, value )
{
if ( Object.defineProperty === undefined )
{
func[ prop ] = value;
}
else
{
Object.defineProperty( obj, prop,
{
value: value,
enumerable: false,
writable: false,
configurable: false,
});
}
}
/**
* Attaches isAbstract() method to the class
*
@ -251,21 +283,7 @@ function attach_abstract( func, methods )
// attach the list of abstract methods to the class
if ( Object.defineProperty === undefined )
{
func.abstractMethods = methods;
}
else
{
Object.defineProperty( func, 'abstractMethods',
{
value: methods,
enumerable: false,
writable: false,
configurable: false,
});
}
define_secure_prop( func, 'abstractMethods', methods );
}
@ -295,19 +313,5 @@ function attach_extend( func )
// if defineProperty is unsupported, do it the old fashioned way (it's just
// less restrictive)
if ( Object.defineProperty === undefined )
{
func.extend = ext_method;
}
else
{
Object.defineProperty( func, 'extend',
{
value: ext_method,
enumerable: false,
writable: false,
configurable: false,
} );
}
define_secure_prop( func, 'extend', ext_method );
}