scope Questions
5
Solved
Learning about Ruby blocks here. What is the point of having block local variable in this example:
When you can just do the below instead? The x in the block is already going to have its own scop...
2
Solved
I've search all over this site and google and I ended up creating this account...
I need some help with php, traits and classes. I have this 2 different traits, that have some methods with the same...
Heddie asked 11/5, 2014 at 17:23
4
Solved
If we execute such two lines in any function, we will get an error, and this is logical because the variable b is defined after the initialization a=b:
int a=b;
int b=0;
But when we insert these t...
Thereinto asked 8/6, 2023 at 7:41
1
I'm creating an iframe dynamically like this:
let code = "<html><head><title> hello world <\/title><\/head><body><h1> hello world <\/h1><scri...
Nunuance asked 24/6, 2020 at 1:26
2
Solved
I was just playing around with event listeners with DOM and Javascript and did notice this:
function chained(msg) {
console.log(msg, event);
}
function onClick() {
chained('the body was clicked'...
Elma asked 21/6, 2011 at 13:58
2
Solved
<script>
var sample = function() {
(function() {
return "something"
})();
// how can I return it here again?
}
</script>
Is there a way to return the returned value from the ano...
Haines asked 29/8, 2011 at 12:0
26
Solved
How do I create or use a global variable inside a function?
How do I use a global variable that was defined in one function inside other functions?
Failing to use the global keyword where appropri...
Dissuasive asked 8/1, 2009 at 5:45
3
Solved
I was given this extensive PowerShell script from a major/reputable corporation which was supposed to work flawlessly. Well, it didn't.
The script is composed of numerous nested functions with lots...
Foist asked 23/4, 2015 at 18:43
4
Solved
Bash seems to behave unpredictably in regards to temporary, per-command variable assignment, specifically with IFS.
I often assign IFS to a temporary value in conjunction with the read command. I ...
2
Solved
I need to use a variable variable for defining a lambda function inside of the callback of array_map(). I get an "Undefined variable" WARNING for the variable that I am referencing. Subse...
Fulmer asked 23/2 at 10:15
13
Solved
There is a lot of code in one of our projects that looks like this:
internal static class Extensions
{
public static string AddFoo(this string s)
{
if (s == null)
{
return "Foo";
}
return ...
10
Solved
According to the most programming languages scope rules, I can access variables that are defined outside of functions inside them, but why doesn't this code work?
<?php
$data = 'My data';
fu...
8
Solved
I'm looking for a way to set the scope of require_once() to the global scope, when require_once() is used inside a function. Something like the following code should work:
file `foo.php':
<?ph...
Comedietta asked 23/1, 2012 at 15:2
8
Solved
I see that the following is fine:
const Tab = connect( mapState, mapDispatch )( Tabs );
export default Tab;
However, this is incorrect:
export default const Tab = connect( mapState, mapDispatch...
Shimberg asked 28/3, 2016 at 11:16
5
Solved
Just out of curiosity: if I have nested scopes, like in this sample C++ code
using namespace std;
int v = 1; // global
int main (void)
{
int v = 2; // local
{
int v = 3; // within subscope
c...
4
Solved
How can I assign a function argument to a global variable with the exact same name?
Note:
I can't do self.myVariable = myVariable because my function is not inside of a class.
When write the foll...
3
Solved
I wonder if it's possible to restrict keyframe animations to a scope based on classnames. The benefit would be to be able to use the same animation-name multiple times without getting issues. I cou...
Laissezfaire asked 5/4, 2018 at 9:16
3
Solved
In setUp() method of unittest I've setup some self variables, which are later referenced in actual tests. I've also created a decorator to do some logging. Is there a way in which I can access thos...
Kimmel asked 28/9, 2011 at 23:4
6
Solved
We put all of our unit tests in their own projects. We find that we have to make certain classes public instead of internal just for the unit tests. Is there anyway to avoid having to do this. What...
Spinal asked 20/9, 2008 at 3:10
1
Solved
I can write the following function f and the code compiles as I would expect:
use std::collections::HashMap;
struct A {
data: HashMap<u32, B>,
}
struct B {
val: Option<u32>,
}
impl...
1
Solved
I struggle to find resources on this, and yet, so many of my classes are running into this error when I compile my code on the latest Java (21).
Here is a code example.
public class ThisEscapeExamp...
Whet asked 28/9, 2023 at 2:30
7
Solved
If I write something like this:
#include <iostream>
int main()
{
using namespace std;
{int n;n=5;} cout<<n;
system("pause");
return 0;
}
The compiler tells me that n is undecla...
9
Is there a POSIX Compliant way to limit the scope of a variable to the function it is declared in? i.e.:
Testing()
{
TEST="testing"
}
Testing
echo "Test is: $TEST"
should print "Test is:". I'v...
3
Solved
In an abstract base class if we have some static fields then what happens to them ?
Is their scope the classes which inherit from this base class or just the type from which it is inheriting (each...
5
Solved
In PHP, how is variable scope handled in switch statements?
For instance, take this hypothetical example:
$someVariable = 0;
switch($something) {
case 1:
$someVariable = 1;
break;
case 2:
...
Talavera asked 21/2, 2010 at 15:0
1 Next >
© 2022 - 2024 — McMap. All rights reserved.