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.

17524 questions
5
votes
3 answers

Only in Safari: ReferenceError Can't find variable

Many of my scripts look like this: if (...) { const myvariable1 = document.querySelector('.class-1'); const myvariable2 = document.querySelector('.class-2'); function someFunction() { // Do something with myvariable1 or…
Sr. Schneider
  • 647
  • 10
  • 20
5
votes
4 answers

Context-preserving eval

We're building a small REPL that evaluates (with eval) javascript expressions as they are being entered by the user. Since the whole thing is event-driven, evaluation must take place in a separate function, but the context (that is, all declared…
georg
  • 211,518
  • 52
  • 313
  • 390
5
votes
5 answers

Class and scope in Javascript

I wrote the following code in Javascript. function main() { this.a ; this.set = function() { a = 1; } } var l = new main(); alert("Initial value of a is "+ l.a ); l.set(); alert("after calling set() value of a is "+ l.a…
Jinu Joseph Daniel
  • 5,864
  • 15
  • 60
  • 90
5
votes
5 answers

Deferring code on scope change in Perl

I often find it useful to be able to schedule code to be executed upon leaving the current scope. In my previous life in TCL, a friend created a function we called defer. It enabled code like: set fp [open "x"] defer("close $fp"); which was…
mmccoo
  • 8,386
  • 5
  • 41
  • 60
5
votes
1 answer

The only option is to include that block of code into each of my functions?

Several of my functions require the UniversalXPConnect privilege to be enabled. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); So, my functions look like this: function oneOfMyFunctions() { …
5
votes
1 answer

How to make large numbers of existing functions available in the scope of a class?

I need to make a large (100's of source files) project into a library, removing dozens of global variables by putting them all into a class object. The problem is the thousand or so functions that now need to be members of this class so they have…
user750895
  • 51
  • 1
5
votes
3 answers

Accessing outer scope in JavaScript

So I've got this JS code here, and I'm trying to set obj from the success and error callbacks, but apparently the toLinkInfo function scope is not a parent scope of those? I always get null back from this function no matter what. I tried a bunch of…
Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
5
votes
1 answer

How are apply family functions scoped?

Consider: x <- 5 replicate(10, x <- x + 1) This has output c(6, 6, 6, 6, 6, 6, 6, 6, 6, 6). However: x <- 5 replicate(10, x <<- x + 1) has output c(6, 7, 8, 9, 10, 11, 12, 13, 14, 15). What does this imply about the environment that x <- x + 1 is…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
5
votes
2 answers

In .Net is the 'Staticness' of a public static variable limited to an AppDomain or the whole process?

Is one copy of a public static variable created for each AppDomain in a process or is it just one copy for the whole process? In other words if I change the value of a static variable from within one AppDomain, will it affect the value of the same…
Harindaka
  • 4,658
  • 8
  • 43
  • 62
5
votes
5 answers

Tips for an intermediate javascript programmer to write better code

So I'm a fairly decent javascript programmer and I've just recently finished working on a fairly big web application that involved writing quite a bit of javascript. One of the things I can across when I was debugging my script was that there were…
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
5
votes
4 answers

Just when I think I finally understand Javascript scope

I run in to something that illustrates how I clearly don't get it yet. Can anyone please explain why the value of "this" changes in the following? var MyFunc = function(){ alert(this); var innerFunc = function(){ alert(this); } …
morgancodes
  • 25,055
  • 38
  • 135
  • 187
5
votes
3 answers

Why is the default scoping behavior in Perl the way that it is?

I am learning Perl for school, and currently am learning about the use of the my keyword and about scoping in Perl. (For reference, I was looking at How should I use the "my" keyword in Perl? .) Hopefully this question hasn't already been asked…
Ryan Blanchard
  • 509
  • 5
  • 11
5
votes
2 answers

Is it safe to assign a struct member pointer to another dynamically memory allocated pointer?

#include #include struct Test { const char *str; }; void test_new(Test *test) { char *s = malloc(100); s[0] = 'H'; s[1] = 'i'; s[2] = '\0'; test->str = s; } int main(void) { struct Test…
Jack Murrow
  • 396
  • 3
  • 11
5
votes
5 answers

What Happens to an Object That Falls Out of Scope in Delphi?

When an object that is created within a function and the function is completed, what happens to the object if it wasn't explicitly destroyed? Do all variables need to be destroyed when they fall out of scope or are they taken care of when they fall…
Dave
  • 5,436
  • 11
  • 48
  • 74
5
votes
2 answers

Compund literals storage duration in C

First question ever :) I'm studying programming "by myself", reading "C Programming: A modern Approach" by K.N.King. In Chapter18 - Declarations, in the Q&A section, there is a question about why selection statements and iteration statements (and…
Masfeo
  • 53
  • 3
1 2 3
99
100