Global no longer uses root as alt object prototype
This is a bugfix; the bug was introduced in v0.2.3. Initially, the implementation created a new object with the root object as its prototype, taking advantage of ECMAScript's native overrides/fallthroughs. Unfortunately, IE<=8 had a buggy implementation, effectively treating the prototype as an empty object. So, rather than alt.Array === root.Array, alt.Array === undefined. The fix is simply to reference discrete objects.textend
parent
d0ec7aca9b
commit
324ff5ddca
|
@ -45,9 +45,11 @@ function Global()
|
||||||
return new Global();
|
return new Global();
|
||||||
}
|
}
|
||||||
|
|
||||||
// allows us to extend the global object without actually polluting the
|
// do not pollute the global scope (previously, _the_global was used as
|
||||||
// global scope
|
// the prototype for a new object to take advantage of native overrides,
|
||||||
this._global = new _G();
|
// but unfortunately IE<=8 did not support this and always returned
|
||||||
|
// undefined values from the prototype).
|
||||||
|
this._alt = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,8 +58,9 @@ function Global()
|
||||||
* versions, for any root variable name, and works with ES5 strict mode.
|
* versions, for any root variable name, and works with ES5 strict mode.
|
||||||
*
|
*
|
||||||
* As an example, Node.js exposes the variable `root` to represent global
|
* As an example, Node.js exposes the variable `root` to represent global
|
||||||
* scope, but browsers expose `window`. Further, ES5 strict mode will provde
|
* scope, but browsers expose `window`. Further, ES5 strict mode will
|
||||||
* an error when checking whether `typeof SomeGlobalVar === 'undefined'`.
|
* provide an error when checking whether `typeof SomeGlobalVar ===
|
||||||
|
* 'undefined'`.
|
||||||
*
|
*
|
||||||
* @return {Object} global object
|
* @return {Object} global object
|
||||||
*/
|
*/
|
||||||
|
@ -86,12 +89,14 @@ Global.prototype = {
|
||||||
*/
|
*/
|
||||||
provideAlt: function( name, f )
|
provideAlt: function( name, f )
|
||||||
{
|
{
|
||||||
if ( typeof this._global[ name ] !== 'undefined' )
|
if ( ( _the_global[ name ] !== undefined )
|
||||||
|
|| ( this._alt[ name ] !== undefined )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._global[ name ] = f();
|
this._alt[ name ] = f();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -112,7 +117,9 @@ Global.prototype = {
|
||||||
*/
|
*/
|
||||||
get: function( name )
|
get: function( name )
|
||||||
{
|
{
|
||||||
return this._global[ name ];
|
return ( this._alt[ name ] !== undefined )
|
||||||
|
? this._alt[ name ]
|
||||||
|
: _the_global[ name ];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue