Added checks for ES5 features
parent
8422bea1d6
commit
61985eea47
29
lib/class.js
29
lib/class.js
|
@ -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 );
|
||||||
},
|
};
|
||||||
|
|
||||||
|
// 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,
|
enumerable: false,
|
||||||
writable: false,
|
writable: false,
|
||||||
configurable: false,
|
configurable: false,
|
||||||
} );
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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' ),
|
||||||
|
|
Loading…
Reference in New Issue