Lexical scoping (sometimes known as static scoping ) is a convention used with many programming languages that sets the scope (range of functionality) of a variable so that it may only be called (referenced) from within the block of code in which it is defined. The scope is determined when the code is compiled. A variable declared in this fashion is sometimes called a private variable.
Questions tagged [lexical-scope]
271 questions
0
votes
0 answers
lexical scoping example not working
Why would this closure not work?
var derivedKey;
lightwallet.keystore.deriveKeyFromPassword(password, function (err, pwDerivedKey) {
derivedKey = pwDerivedKey;
});
if (!derivedKey){
console.error ("ERROR no derivedKey");
}
Thows…

Roland Kofler
- 1,332
- 1
- 16
- 33
0
votes
1 answer
javascript: closures, anonymous functions, iife
A friend asked me to design a function that does the following : f1()()()()(0)
should give the output as 4. f1()(0) should give output as 1. It is the number of preceding parentheses before 0 is passed. I searched thoroughly on how it should be…

Prabhat Saini
- 1
- 1
0
votes
2 answers
R: Create a function within a function, passing arguments as defaults
I am developing a function that returns another function of a particular form (linear or asymptotic, indicated by the "FuncType" argument). I would like to assign a vector of default values to the "params" argument of the function to be returned.
#…

Nate L
- 3
- 1
0
votes
1 answer
for in loop weird behavior
I've got some weird behavior with a for-in loop.
Code:
var obj = {
q:1,
w:2,
e:4,
r:5
};
function test(data) {
for (key in data) {
//do sth;
}
}
!function() {
for (key in obj) {
console.log(key);
…

r0ck
- 173
- 12
0
votes
2 answers
Where should I add the magic comment of lexical-binding?
The first line of a .el file used to be
;;; foo.el - a foo package
Does it works if the magic comment is added after this?
;;; foo.el - a foo package
;;; -*- lexical-binding: t -*-
Or even later in the file?

tom
- 1,302
- 1
- 16
- 30
0
votes
3 answers
lexical scopes for function expressions
If we divide the operation of javascript engine into compilation phase (where that whole lexical scope diagram is setup) Vs running phase (where code is executed using lexical scope setup in compilation phase), when is the scope for function…

noi.m
- 3,070
- 5
- 34
- 57
0
votes
3 answers
Javascript Lexical scope
I am trying to understand the concept of Lexical scope. As far as i know Lexical scope does not work backwards. In the below javascript code i have declared variable 'name' in scope3() function. But i tried to call it in scope1() and scope2()…

SsNewbie
- 257
- 2
- 8
- 21
0
votes
1 answer
Lexical Scope/Closures and Global Function Recursion
This is both an example of lexical scoping and a question to confirm my own understanding. First, consider the following example:
Html:
JS:
function fnTest(currentIdx, endIdx) {
$('#testtxt').html($('#testtxt').html() +…

Ian
- 4,169
- 3
- 37
- 62
0
votes
1 answer
Manipulating PHP arrays using references like JS objects
I am manipulating an array, as shown below, in JavaScript.
http://ideone.com/vH43iD
array(
'1'=>array(
'id'=>'1',
'nodes'=>array(
'4'=>array(
…

Oğuzhan Eroğlu
- 152
- 1
- 10
0
votes
0 answers
Is it possible to change binding in the parent frame?
I try to create closure where in parent frame exists binding with name inner which only can be accessibly using methods I provide by return.
Here is my code:
def test():
inner = 'value'
def get_inner():
return inner
def…

SuperManEver
- 2,263
- 6
- 28
- 36
0
votes
1 answer
Outer function returns an inner function with access to values from outer function
I need to create a function which I will pass to my database server. The returned function will take a single item as a parameter and compare that item to a list of requirements.
For this I need a function generating function that takes an array as…

Ryan Harrigan
- 23
- 4
0
votes
1 answer
Bubbling scope - Updating var from nested function
I'm updating a variable from an outer scope in a nested function,
as this is happening during a init function the outer scope isn't the outermost (window) scope;
var init = function() {
var x = 'old stuff' ;
function butClick() {
…

maioman
- 18,154
- 4
- 36
- 42
0
votes
1 answer
Code not evaluated in default argument value specification
(At least some kind of) Ruby code is accepted and evaluated within the default value specification of a method. In below, "foo" * 3 is evaluated:
def bar baz = "foo" * 3; baz end
bar # => "foofoofoo"
def bar baz: "foo" * 3; baz end
bar # =>…

sawa
- 165,429
- 45
- 277
- 381
0
votes
1 answer
Lexical scoping / calling stack issue: R fails to recognize an argument's default value
This is sort of the strangest thing I ever encountered in R.
Is it possible, that certain argument names (lazy in my case) are special/reserved and thus would lead to unexpected behavior when a calling stack is involved that spreads across functions…

Rappster
- 12,762
- 7
- 71
- 120
0
votes
2 answers
How to use transformations to variables in formulas in R
I'm trying to use transformations of my outcomevar in a function that runs a few variants of models and stores the result in a list.
The runpanelsfunction first calls the prepare data function, which creates the lagged and differenced variables of…

TinaW
- 989
- 1
- 18
- 28