Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 10th, 2012  |  syntax: None  |  size: 0.35 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. assigning a function to a name globally
  2. f(function(){ /* code */ }, "foo");
  3.  
  4. foo(); // this call should now work!
  5.        
  6. function f(g, n) {
  7.     this[n] = g;
  8. }
  9.        
  10. function f(g, n) {
  11.     (function() { return this; })()[n] = g;
  12. }
  13.        
  14. var addGlobalFunction = (function(global) {
  15.     return function (fn, name) {
  16.         global[name] = fn;
  17.     };
  18. })(this);