Declaring global variable inside a function

declare inside a function doesn’t work as expected. I needed read-only global variables declared in a function. I tried this inside a function but it didn’t work: declare -r MY_VAR=1 But this didn’t work. Using the readonly command did: func() { readonly MY_VAR=1 } func echo $MY_VAR MY_VAR=2 This will print 1 and give the … Read more

Is ‘window’ really global in JavaScript?

The reason why you can access “out of scope” or “free” variables in ECMAScript is the so-called scope chain. The scope chain is a special property from each execution context. As mentioned several times before, a context object looks at least like: [[scope]] Variable / Activation Object “this” context value Each time you access a … Read more

C++ redeclaration of loop count variable inconsistent behaviour?

According to the standard specification: 1 … names declared in the for-init-statement are in the same declarative-region as those declared in the condition 3 If the for-init-statement is a declaration, the scope of the name(s) declared extends to the end of the for-statement. [§6.5.3] and 4 Names declared in the for-init-statement, the for-range-declaration, and in … Read more

Spring Service default scope

Which is the default scope of a Spring 4 @Service? The default scope is singleton It is reasonable to design a Service implementation in order to store some info, related to the current logged user (according to the current HTTP session) Yes. In that case, the service will have to have the scope “session”. See … Read more

What happens when JavaScript variable name and function name is the same?

Functions are a type of object which are a type of value. Values can be stored in variables (and properties, and passed as arguments to functions, etc). A function declaration: Creates a named function Creates a variable in the current scope with the same name as the function (unless such a variable already exists) Assigns … Read more

tech