Every line of 'how to declare global variable in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
6 export function addGlobal(prop, val) { 7 return window && (() => window[prop] = val)(); 8 }
49 _bindVariable(varName) { 50 if (varName in this._revbinders) 51 return this._revbinders[varName]; 52 53 let binder = this._nextbinder++; 54 this._binders[binder] = varName; 55 this._revbinders[varName] = '?' + binder; 56 return '?' + binder; 57 }
45 export function setVariable (name, value) { 46 pushEvent({ [name]: value }); 47 }
163 function setVariable(name, value, variables) { 164 // Variable can be nested 165 var path = name.split('.'); 166 var currentVars = variables; 167 168 for (var i = 0; i < path.length; i++) { 169 // TODO allow for arrays in variables 170 if (i == path.length - 1) { 171 currentVars[path[i]] = value; 172 } else { 173 // Create the object if not available 174 if (!currentVars.hasOwnProperty(path[i])) { 175 currentVars[path[i]] = {}; 176 } 177 178 currentVars = currentVars[path[i]]; 179 } 180 } 181 }
28 function hasInGlobal(name) { 29 // name: dot ok 30 var g=window; 31 name.split(".").forEach(function (e) { 32 if (!g) return; 33 g=g[e]; 34 }); 35 return g; 36 }
6 get(variable) { 7 return this.data[variable] 8 }
32 export function getGlobal(): any { 33 if (typeof self !== "undefined") { // WebWorkers 34 return self; 35 } 36 if (typeof window !== "undefined") { // Browsers 37 return window; 38 } 39 if (typeof global !== "undefined") { // Serverside (Node) 40 return global; 41 } 42 // Otherwise, try to use `this`. 43 // We use eval-like behavior, because it will not inherit our "use strict", 44 // see http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript 45 let g: any; 46 try { 47 g = new Function("return this")(); 48 } catch (e) { 49 // Content Security Policy might not allow the eval()-evilness above, 50 // so just ignore then... 51 } 52 return g; 53 }
61 forEachVariable(callback, thisObj) { 62 if (!this.nestedVariables) { 63 return; 64 } 65 66 this.nestedVariables.vars.forEach(callback, thisObj); 67 }
12 function getQueryVariable(variable) { 13 let query = window.location.search.substring(1); 14 let vars = query.split("&"); 15 for (let i = 0; i < vars.length; i++) { 16 let pair = vars[i].split("="); 17 if (pair[0] == variable) { return pair[1]; } 18 } 19 return (false); 20 }
70 public define(scope: Scope, name: string, value: BrsType): void { 71 let destination: Map; 72 73 switch (scope) { 74 case Scope.Function: 75 destination = this.function; 76 break; 77 case Scope.Module: 78 destination = this.module; 79 break; 80 default: 81 destination = this.global; 82 break; 83 } 84 85 destination.set(name.toLowerCase(), value); 86 }