1
0
Fork 0

Added checks for ES5 features

closure/master
Mike Gerwitz 2010-11-10 23:28:20 -05:00
parent 8422bea1d6
commit 61985eea47
2 changed files with 34 additions and 11 deletions

View File

@ -22,6 +22,12 @@
* @package core * @package core
*/ */
// whether getters/setters are supported
var getset = ( Object.prototype.__defineGetter__ === undefined )
? false
: true
;
/** /**
* Default class implementation * Default class implementation
@ -52,8 +58,8 @@ var prop_copy = function( props, dest )
// care about methods - properties will simply have their values // care about methods - properties will simply have their values
// overwritten) // overwritten)
var pre = dest[ property ], var pre = dest[ property ],
getter = props.__lookupGetter__( property ), getter = ( ( getset ) ? props.__lookupGetter__( property ) : null ),
setter = props.__lookupSetter__( property ); setter = ( ( getset ) ? props.__lookupSetter__( property ) : null );
// check for getter/setter overrides // check for getter/setter overrides
if ( getter || setter ) if ( getter || setter )
@ -166,15 +172,26 @@ var attach_extend = function( func )
* *
* @return {Object} extended class * @return {Object} extended class
*/ */
Object.defineProperty( func, 'extend', var ext_method = function( props )
{ {
value: function( props ) return extend( this, props );
{ };
return extend( this, props );
},
enumerable: false, // if defineProperty is unsupported, do it the old fashioned way (it's just
writable: false, // less restrictive)
configurable: false, if ( Object.defineProperty === undefined )
} ); {
func.extend = ext_method;
}
else
{
Object.defineProperty( func, 'extend',
{
value: ext_method,
enumerable: false,
writable: false,
configurable: false,
} );
}
} }

View File

@ -22,6 +22,12 @@
* @package test * @package test
*/ */
// don't perform these tests if getters/setters are unsupported
if ( Object.prototype.__defineGetter__ === undefined )
{
return;
}
require( './common' ); require( './common' );
var assert = require( 'assert' ), var assert = require( 'assert' ),