Created
March 5, 2011 06:42
-
-
Save subtleGradient/856186 to your computer and use it in GitHub Desktop.
Globalize JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Foo = 'bar'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.Foo = 'bar'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var global = function(){return this || (1,eval)('this')}(); | |
| global.Foo = 'bar'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !function(){ | |
| var GLOBAL = function(){return this || (1,eval)('this')}() | |
| Function.prototype.globalize = function(){ | |
| return this.apply(GLOBAL, arguments) | |
| } | |
| }() | |
| !function(){ | |
| this.Foo = 'bar'; | |
| }.globalize() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Export(fn){var G = this||(7,eval)('this'); fn.call(G,G)} | |
| Export (function(exports){ | |
| exports.Foo = 'bar'; | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Export(fn){fn.call(this||(7,eval)('this'))} | |
| Export (function(){ | |
| this.Foo = 'bar'; | |
| }) |
Author
yeah, but potentially use eval in every single module? I dislike.
Author
What's the alternative?
You have to get Export or applyGlobal into the universe somehow.
the upside of applyToGlobal is that you only have to get the context once and reuse that on every function call.
Like I had mentioned on another comment.. is this possible as well?
var global = this || (1, eval)('this');
global.global = global;
(function(){
this....
}).call(global);
// or I guess directly:
global.Function.prototype....
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we can handle 53 characters at the top of each file ;)