Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!(
- { "date_modified":"+2019-01-17"
- , "author_name":"R.V.Klein"
- , "author_url":"https://rvklein.me"
- , "title":"Demonstration of runtime scope deduction in JS/ES"
- })!*/
- var _=_(this);function _(that)
- {'use strict';
- function isOwnConstructor (x)
- {
- return(
- ( ('object'===typeof(x))
- && (x.constructor.name in x)
- && (x instanceof x[x.constructor.name])
- && ('function'===typeof(x.constructor.constructor))
- && (x.constructor.constructor instanceof Function)
- && (Function===x.constructor.constructor)
- )
- ?true:false);
- }
- var _={scope:{that:undefined},scopeType:undefined,_hasStrictMode:undefined};
- try{if(isOwnConstructor(this)){_._hasStrictMode=false;}else{_._hasStrictMode=true;}}catch(e){};
- if(that&&isOwnConstructor(that)){_.scope.that=that;}
- try{if(isOwnConstructor(self)){_.scope.self=self;}}catch(e){};
- try{if(isOwnConstructor(global)){_.scope.global=global;}}catch(e){};
- try{if(isOwnConstructor(window)){_.scope.window=window;}}catch(e){};
- try{_._currentScript=_.window.document.currentScript;}catch(e){};
- if(('self' in _.scope)&&((!_.scope.that)||(_.scope.that===_.scope.self))){ _.scopeType='self'; }
- if(('global' in _.scope)&&('Object'===_.scope.global.constructor.name)&&((!_.scope.that)||(_.scope.that===_.scope.global))){ _.scopeType='global'; }
- if(('window' in _.scope)&&('Window'===_.scope.window.constructor.name)&&((!_.scope.that)||(_.scope.that===_.scope.window))&&('document' in _.scope.window)){ _.scopeType='window'; }
- return(_);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement