Questions tagged [scope]
Scope is an enclosing context where values and expressions are associated. Use this tag for questions about different types of scope as well for questions where scope may be unclear.
16,859
questions
-1
votes
1
answer
14
views
If fetch returns object with multiple attributes (ie. object.exists and object.message) how can I use them after fetch is done?
After fetch returns object it logs it perfectly and I can see all attributes in the object. I can even change the html in the page using all the attributes.
login_button=document.getElementById('...
0
votes
3
answers
34
views
How to access a variable outside of a class function if it wasn't passed to the function
I have been tasked to modify the behavior of a function in one of our Python classes.
Our function takes a few parameters, one being a debug flag. Currently the if the debug flag is not specified then ...
1
vote
2
answers
49
views
How to check, how often have dynamically created buttons been clicked, individually and in total?
I created a loop with buttons in it. I also created an eventListener that keeps a count for every button. I want something to happen when all buttons have been presses at least 3 times, so I created ...
0
votes
0
answers
15
views
Does Swift uses static or dynamic scoping?
I'm reading an article that saying that Swift uses either static or dynamic scoping? Can you enlighten me? Thank you.
-1
votes
0
answers
10
views
I'm stuck with async/await and scope [duplicate]
So I use async/await to get the value out of Promise. But then this value is accessible only within the scope of a function and I don't know how to use it in JSX. I'm stuck and will be grateful for ...
0
votes
0
answers
35
views
Can I get a mixture of := and = in Go if statements? [duplicate]
Go newbie here...
If func returns a value and an error, can I write an if statement so the value stays in scope after the if statement, but the error does not? That is a common thing I want to do, and ...
0
votes
1
answer
14
views
how can i import main functin of another dart file
How can I verify that a print is called for in dart unit tests?
I am writing a sample code for textbooks and want to try it out. There are many examples that use printing for simplicity. I want to run ...
0
votes
0
answers
28
views
How does function within addEventListener gets hoisted?
I found a weird behavior that I couldn't understand even reading MDN doc about hoisting.
It says that functions and variables gets moved to the top of the scope except variable initialization. So how ...
0
votes
0
answers
15
views
Functions and hoisting related question in Javascript [duplicate]
const fun = () => console.log(variable);
let variable;
variable = 'some string';
fun();
Hello, guys I,m interested how JS works in this situation. In the function declaration I'm logging ...
0
votes
1
answer
19
views
How do I create a scoped class without @include?
I managed to create a scoped CSS class like this:
.container {
@import "./baa";
/* other props ... */
}
but since @import is getting depreciated, what are my options to make a ...
0
votes
2
answers
83
views
Local variable initialized inside 'if' is still available after that 'if' in C#
Have not found an answer to this question yet (proboply because I am looking wrong for it). I was just wondering following. Why is it not possible to have this code:
if (obj is string str) {
// do ...
-1
votes
1
answer
21
views
Convert list of class objects to list of lists [duplicate]
My goal is to write a function, which receives a list of class objects and converts these into a list of lists, this is what I currently have:
def convertToListOfLists(toConvert):
listOfLists = []
...
0
votes
2
answers
30
views
Python boolean variable not updating within a loop
I have two pieces of python code that I expect to give me the same result but that is not happening. I wrote the following routine for a fill type question on leetcode and got the wrong answer
def ...
1
vote
1
answer
32
views
error: expected unqualified-id before ‘friend’
In my .cpp file I got
Student:: friend istream& operator>>(istream &input,Student &a){
input>>a.AM>>a.name>>a.semester>>;
return input;
}
...
0
votes
2
answers
32
views
Is it possible in Javascript to ACTUALLY pass an array as reference? [duplicate]
Is it possible in Javascript to pass an array (from outer scope) to a function, and mutate the original array?
I've read several answers mentioning that f()'s arr argument is actually a copy, it's ...
2
votes
1
answer
55
views
When does the parent thread synchronize with an ada task type variable with a non-global scope?
I was working on some multithreaded Ada network code, which involved accepting and handling multiple connections in parallel. An ideal situation for the use of Ada tasks, no? Specifically, multiple ...
0
votes
3
answers
77
views
why does returning the local variable address throws an error but returning the local variable value don't? [duplicate]
I can not understand, what is the difference between following function bodies
int func(void){
int A = 20;
return A;
}
and
int* func(void){
int A = 20;
return &A;
}
why returning ...
0
votes
1
answer
44
views
Scoping issue with instance attributes and Class methods in tkinter/customtkinter
My tkinter/customtkinter GUI uses multiple frames raised above one another. I have a two frames both containing switches that need to invert one another (ie when one is 'ON' the other must be 'OFF'). ...
0
votes
2
answers
21
views
Java Neo4j Transaction: how can I access transaction declared in try-header in catch blocks?
I have this:
try(Transaction t = sess.beginTransaction()){
// do something with t...
} catch (Exception e) { // abort transaction if something goes wrong
...
t....
0
votes
0
answers
47
views
Trying to understand why this switch case example works on arduino
Im new to C++, only having done some bash scripting for a few years a while back, and my only other experience was with BASIC some 30 years ago.
I started with a (what i thought would be) a simple ...
0
votes
3
answers
42
views
Can extern make a function variable a global variable?
As I understood extern makes a variable --> global variable, so it means we can also make variable of another function a global variable?
#include <stdio.h>
extern char* name;
void ...
0
votes
0
answers
30
views
How to access variable from a function in a required file that required another file? Can I do it directly, without using $GLOBALS? [duplicate]
So I have the following 3 files:
index.php
<?php
require("require/functions.php");
$g = getGroup();
var_dump($data);
die();
?>
functions.php
<?php
function ...
1
vote
0
answers
20
views
Mocking scope function in Kotlin
I am using following object creation methods in kotlin
class Resource(
referenceFactory: ReferenceFactory,
id: String,
name: String,
role: ...
1
vote
2
answers
39
views
Svelte reactive statement with a variable fron onMount
I'm trying to style the currently active tab of my web project with the class "active". To target my tab elements I am using
onMount(() => {
const links = document....
1
vote
1
answer
42
views
C++, Where To Put Free Variables?
I'm writing a small ini file parser (0), I use some regular expressions that I have put into a std::map<std::string, std::regex>, it's a const one because it contains all I need to retrieve the ...
0
votes
0
answers
25
views
Static class with unique id per request
I want to achieve something similar (but much simpler) like Serilog sinks without using DI explicitly.
It's easy to do with DI you just have to register service as scoped and just create id when ...
0
votes
0
answers
27
views
PHP Undefined function when calling function from included file inside class method
So, i created the view method :
<?php
namespace MYAPP\Controller;
/**
* Site controller
*/
class Site extends Controller
{
// ... other method and variable
/**
* Load theme file
...
0
votes
0
answers
8
views
How to define a Python function that uses the outer variables' values at the time of function definition? [duplicate]
I want to define many Python functions that use variables from the outer scope, as shown in the following code:
functions = []
for i in A:
for j in B:
def c(x):
return i*x+j*(x**2)...
0
votes
0
answers
15
views
Problem accessing values globally due to event listener's function scope
Hello guys and thanks for the help.
compileDescription here is a function I called in order to create the description page of an ecommerce. I received the products passed as an argument from an api, ...
1
vote
0
answers
33
views
How can I determine if I'm inside Jersey request scope?
I have some code that will run both inside Jersey request context and outside of Jersey request context (in another thread). I have a piece of data I want to access in both cases that's optional, but ...
1
vote
0
answers
26
views
Is there a way to prevent sourced scripts in POSIX sh from running anything in global scope?
I'm making a thing which has to source
a POSIX shell script (NOT BASH) as its configuration
file, but it should only have definitions of variables,
functions and comments, nothing else like running ...
0
votes
0
answers
27
views
Getting an Array out of a nested fetch function
so im fetching some data from the PUBG Api, and pushing the needed data into an array called "playerRecentStats", but whenever i try to take this array out of the function i get an undefined ...
0
votes
1
answer
101
views
How does the compiler not confuse local variable named size with function call size()?
While reading a C++ textbook, I came across this specific piece of code:
vector<double> homework;
typedef vector<double>::size_type vec_sz;
vec_sz size = homework.size();
I wonder how isn'...
0
votes
0
answers
8
views
LinkedIn products to subscribe to get access to messaging api
We are tech start-up developing an application and would like to utilise the messaging and connections api.
It looks like this would require special approval from you since the API documentation is ...
0
votes
0
answers
53
views
Ruby - Automatically pass binding() to method like eval?
Ruby 2.7.0
I am writing something similar in vein to the 'eval' method, and I'm realizing there seems to be some magic happening.
Ruby's Kernel#eval has the ability to be given a binding, but somehow ...
0
votes
1
answer
47
views
When accessing a public var that's been modified inside a for loop, i cannot see a change [closed]
I have a public variable which we call Tpus, I modify this value within an infinite for loop, however i get 2 different results when i try to print Tpus in the for loop, and in a goroutine outside the ...
3
votes
1
answer
54
views
Can a function return a representation of what was passed?
Example for clarity:
def foo(arg1):
<function goes here>
x = 5
foo(x > 4)
# foo() should return "x > 4" here.
# I do not want it to return the value, True.
It's for a ...
-1
votes
0
answers
13
views
How to access JavaScript event.currentTarget outside the event?
I am trying to create a page where if people click on a 'more info' link they are directed to a page where they get the details of that following person. However, when I import the function, I cannot ...
1
vote
1
answer
49
views
R: environment diagram for decorator function
I want to draw an environment diagram for the following code which contains an error to understand how R works exactly when evaluating a function.
# emphasize text
emph <- function(f, style = '**') ...
1
vote
1
answer
75
views
Initialize struct with Box<None> value
I am trying to make a flashcard program in rust, that will be saved in json format. I have made this struct for each card:
#[derive(Serialize, Deserialize)]
struct Card{
question:String,
...
-1
votes
2
answers
30
views
Using a list comprehension and string formatting on class properties [duplicate]
Here is the basic class code:
class test:
for i in range(10):
exec(f'a{i}={i+1}')
My first attempt to create the list a_all was to do the following:
exec(f'a_all=[test.ak for k in range(0,...
0
votes
1
answer
33
views
How can I use member functions of google unit test case in thread defined in the unit test?
I have a google unit test where I've defined a few functions in it. It looks like the following
class MyUnitTest {
protected:
void SetUp() override;
void TearDown() override;
void ...
2
votes
1
answer
35
views
PowerShell Group-Object no longer splitting objects into fixed-size collections
I had this in a script which I believe was working well, but appears to have stopped working:
$testList = @("object 1","object 2","object 3","object 4","...
-1
votes
2
answers
32
views
How to get out values from java interface
I have a variable inside an interface method and I want it outside the interface:
String responseString;
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener&...
1
vote
0
answers
17
views
my variable is having a persistent null value outside the ValueEventListener
I don't have much experience with Java. I need to get value from Firebase realtime database and return this value outside listener.
My code is:
public void AtualizaTotaisUSU(){
...
0
votes
1
answer
29
views
When I am running my showLocation function 5 times, I get nothing as a response
so when i run this program,
#include<iostream>
#include<ctime>
float ex, ey;
class Enemy
{
public:
float x, y;
Enemy()
{
x = ex;
...
0
votes
0
answers
12
views
Nested functions not affecting objects in bidimensional array declared within global scope
I have a bidimensional array filled with Cell objects.
How can I do to make addToGrid(asset); (and nested functions) use the context of each Cell to set cells so that I can use it in draw method ?
...
0
votes
3
answers
61
views
Problem with returning an array to a function in C
My problem is that I can't return the processed string to the function. The function's job is that it must accept a string, change its letters, and return the processed string to the function.
char *...
-1
votes
0
answers
25
views
Which scope(s) is/are used in Javascript? [duplicate]
My question is about what scope(s) is/are used in this code? Here a is used inside the function as in static scoping, but i is also used as in dynamic scoping. That's why i am confused. Is the ...
1
vote
1
answer
17
views
YDNJS: scope and closures hoisting wrong example [duplicate]
I am reading YDNJS: scope and closures, And in chapter 4 which talks about hoisting it says that
Function declarations that appear inside of normal blocks typically hoist to the
enclosing scope, ...