SHARE
TWEET

"Demonstration of runtime scope deduction in JS/ES"

a guest Jan 17th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!(
  2. {   "date_modified":"+2019-01-17"
  3. ,   "author_name":"R.V.Klein"
  4. ,   "author_url":"https://rvklein.me"
  5. ,   "title":"Demonstration of runtime scope deduction in JS/ES"
  6. })!*/
  7.  
  8. var _=_(this);function _(that)
  9. {'use strict';
  10.  
  11.     function isOwnConstructor (x)
  12.     {
  13.         return(
  14.             (   ('object'===typeof(x))
  15.             &&  (x.constructor.name in x)
  16.             &&  (x instanceof x[x.constructor.name])
  17.             &&  ('function'===typeof(x.constructor.constructor))
  18.             &&  (x.constructor.constructor instanceof Function)
  19.             &&  (Function===x.constructor.constructor)
  20.         )
  21.         ?true:false);
  22.     }
  23.    
  24.     var _={scope:{that:undefined},scopeType:undefined,_hasStrictMode:undefined};
  25.  
  26.     try{if(isOwnConstructor(this)){_._hasStrictMode=false;}else{_._hasStrictMode=true;}}catch(e){};
  27.     if(that&&isOwnConstructor(that)){_.scope.that=that;}
  28.  
  29.     try{if(isOwnConstructor(self)){_.scope.self=self;}}catch(e){};
  30.     try{if(isOwnConstructor(global)){_.scope.global=global;}}catch(e){};
  31.     try{if(isOwnConstructor(window)){_.scope.window=window;}}catch(e){};
  32.  
  33.     try{_._currentScript=_.window.document.currentScript;}catch(e){};
  34.  
  35.     if(('self' in _.scope)&&((!_.scope.that)||(_.scope.that===_.scope.self))){ _.scopeType='self'; }
  36.     if(('global' in _.scope)&&('Object'===_.scope.global.constructor.name)&&((!_.scope.that)||(_.scope.that===_.scope.global))){ _.scopeType='global'; }
  37.     if(('window' in _.scope)&&('Window'===_.scope.window.constructor.name)&&((!_.scope.that)||(_.scope.that===_.scope.window))&&('document' in _.scope.window)){ _.scopeType='window'; }
  38.  
  39.     return(_);
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top