Questions tagged [global-scope]

Global scope defines a namespace that is fully accessible in the entire program or script.

Global scope defines a namespace that is fully accessible in the entire program or script. Variables, classes and objects that are defined in the global scope can usually be accessed anywhere in the code, and are often referred to as global variables.

108 questions
0
votes
1 answer

Javascript global scope variables accessed later in a script tag with src

I want to be able to pass variables from php into my javascript code in order to save a given users high score. I have done that successfully by at the top of my page by declaring:
Rob
  • 43
  • 3
0
votes
1 answer

Bring variable value from Block to Global Scope (in FIRESTORE)

I'm creating an App in Firebase, using FireStore as my Database. In the code below, I create a variable order and assign it a value of 1. Then I update the value to the number 4 and console.log it to check. Which turns out fine. But when I log the…
0
votes
4 answers

How to sort global scope by attribute LARAVEL

I usually sort the records by a column using global scopes on my model, but I need to order it by an attribute. protected static function boot() { parent::boot(); static::addGlobalScope('order', function (Builder $builder) { …
0
votes
1 answer

Data are not being downloaded after migrate to androidx

After migrating to androidx, my room repositories based on LiveData and GlobalScope.launch stopped working. I changed GlobalScope.launch to GlobalScope.async, because i got exception with observeForever (but I event don't use this method). …
pjp
  • 157
  • 1
  • 12
0
votes
1 answer

What is the global scope in javascript? How can I create one?

When running code on Chrome Inspector's console and typing the this keyword, I can see the global scope object that is exposed with many properties already set. But, how can I create mine? Or when I call a function, the call-site is the "global…
Anderson Anizio
  • 143
  • 1
  • 2
  • 12
0
votes
1 answer

How to declare at beginning of program

In the listing below, an attempt to declare the rectangle "r" before the main() function is called results in an error. error: 'r' does not name a type r.x = 150;
Why must "r" be declared after main()? #include int main (int…
jwzumwalt
  • 203
  • 2
  • 11
0
votes
1 answer

Aren't all function in setTimeout executed in global scope?

I thought all the functions in setTimeout are executed in global scope. Then I saw this today: for(let x = 0; x < items.length; x++){ setTimeout(function() { console.log(x); }) } Even with a value for x in…
Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
0
votes
3 answers

Making a local scope inside a for loop, into a global scope

I have been searching but I cant get a clear answer. (I am a beginner in javascript and this is a test/practice inside the console) How can I make a local scope within a for loop, a global scope so I can then add it to variable with an array of…
0
votes
1 answer

Apply global scope based on user role in Laravel 5.5

For some model, I need to apply a global scope if the logged in user is not super admin. In model's boot() method I tried something like this:
0
votes
3 answers

boxSize leaking to globalscope

Console log two times but it needs to show only the first console.log(boxSize) var size = 100; if (size > 50) { var boxSize = size * 5; console.log(boxSize); } console.log(boxSize);
user8274658
0
votes
1 answer

Bug with GlobalScope in Laravel 5.4

When I try ti use global scope in my model: protected static function boot() { parent::boot(); static::addGlobalScope(new PostScope(Post::TYPE_VIDEO)); static::addGlobalScope('video', function (Builder $builder) { …
0
votes
0 answers

How to limit results by user globally in Eloquent?

I am using eloquent as part of a slim 3 project with slim-jwt-auth (https://github.com/tuupola/slim-jwt-auth), outside of Laravel. There are many situations where I want to control the items returned based on the user who is making the request. From…
Finglish
  • 9,692
  • 14
  • 70
  • 114
0
votes
0 answers

Singleton created twice

In Laravel 5.4 I have registered a Service Provider that creates a singleton to my Context class which holds application context. ContextServiceProvider namespace App\Providers; use Illuminate\Support\ServiceProvider; use App; class…
ArisS
  • 146
  • 8
0
votes
1 answer

Is there any difference between a global function and wrapping such function into a namespaced class?

Suppose you have a global method(). You can move it into a namespace and a class, and call it something like \\Namespace\Class::method(); Is there any difference? Is one better than another? Essentially you have not change anything and the method…
Dennis
  • 7,907
  • 11
  • 65
  • 115
0
votes
1 answer

python global variable scope confusion. What are these variables not accessible?

I see there are a few of these questions on here, but I haven't found one that quit matches what I'm after. I have a common file, lets call it tools.py. In this file I have a host of path definitions to use and an init_paths function to set some…
Jared Sanchez
  • 67
  • 1
  • 10