util.canFreeze removed, replaced with util.freeze()
parent
c29bd010b0
commit
b3c4b757e7
|
@ -22,8 +22,7 @@
|
||||||
* @package core
|
* @package core
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var util = require( './util' ),
|
var util = require( './util' );
|
||||||
can_freeze = require( './util' ).canFreeze();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,10 +131,7 @@ var extend = ( function( extending )
|
||||||
|
|
||||||
// lock down the new class (if supported) to ensure that we can't add
|
// lock down the new class (if supported) to ensure that we can't add
|
||||||
// members at runtime
|
// members at runtime
|
||||||
if ( can_freeze )
|
util.freeze( new_class );
|
||||||
{
|
|
||||||
Object.freeze( new_class );
|
|
||||||
}
|
|
||||||
|
|
||||||
// we're done with the extension process
|
// we're done with the extension process
|
||||||
extending = false;
|
extending = false;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* @package core
|
* @package core
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var can_freeze = require( './util' ).canFreeze();
|
var util = require( './util' );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,11 +53,8 @@ function extend()
|
||||||
|
|
||||||
var new_interface = {};
|
var new_interface = {};
|
||||||
|
|
||||||
// freeze the interface (preventing additions) if supported
|
// freeze the interface (preventing additions), if supported
|
||||||
if ( can_freeze )
|
util.freeze( new_interface );
|
||||||
{
|
|
||||||
Object.freeze( new_interface );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_interface;
|
return new_interface;
|
||||||
}
|
}
|
||||||
|
|
20
lib/util.js
20
lib/util.js
|
@ -34,16 +34,22 @@ var getset = ( Object.prototype.__defineGetter__ === undefined )
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the Object.freeze() method is available
|
* Freezes an object if freezing is supported
|
||||||
*
|
*
|
||||||
* @return {boolean}
|
* @param {Object} obj object to freeze
|
||||||
|
*
|
||||||
|
* @return {Object} object passed to function
|
||||||
*/
|
*/
|
||||||
exports.canFreeze = function()
|
exports.freeze = function( obj )
|
||||||
{
|
{
|
||||||
return ( Object.seal === undefined )
|
// if freezing is not supported (ES5), do nothing
|
||||||
? false
|
if ( Object.freeze === undefined )
|
||||||
: true
|
{
|
||||||
;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.freeze( obj );
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue