It seems that in language like C, Java, and Ruby (as opposed to Javascript), a new scope is created for each iteration of a loop block, and the local variable defined for the loop is actually made into a local variable every single time and recorded in this new scope?
For example, in Ruby:
p RUBY_VERSION
$foo = []
(1..5).each do |i|
...
In Javascript, I am sometimes too immerged in the idea that a function creates a new scope, that sometimes I even think the following anonymous function will create a new scope when it is being defined and assigned to onclick:
<a href="#" id="link1">ha link 1</a>
<a href="#" id="link2">ha link 2</a>
<a href="#" id="link3">ha link 3</a>
...
If the with statement in Javascript creates a new scope, shouldn't clicking on the links show a different x which are in different scopes? It doesn't...
<a href="#" id="link1">ha link 1</a>
<a href="#" id="link2">ha link 2</a>
<a href="#" id="link3">ha link 3</a>
<a href="#" id="link4">ha link 4</a>
<a href="#" id="link5">ha link 5</a>...
I have a main function in A.cpp which has the following relevant two lines of code:
B definition(input_file);
definition.Print();
In B.h I have the following relevant lines of code:
class B
{
public:
// Constructors
B(void);
B(const char *filename);
~B(voi...
This scoping problem seems like the type of C++ quandary that Scott Meyers would have addressed in one of his Effective C++ books.
I have a function, Analyze, that does some analysis on a range of data. The function is called from a few places with different types of iterators, so I have made it a template (and thus implemented it in a...
I like HAML. So much, in fact, that in my first Rails app, which is the usual blog/CMS thing, I want to render the body of my Page model using HAML (obviously I won't do the same for Comment!). So here is app/views/pages/_body.html.haml:
.entry-content= Haml::Engine.new(body, :format => :html5).render(self)
...and it works (yay, recur...
I'm writing a program in python that uses genetic techniques to optimize expressions.
Constructing and evaluating the expression tree is the time consumer as it can happen
billions of times per run. So I thought I'd learn enough c++ to write it and then incorporate it
in python using cython or ctypes.
I've done some searching on st...
I'm writing an application in javascript and cannot figure it out how to access the variables declared in my function, inside this jquery parse. Inside I can access global variables, but I don't really want to create global vars for these values.
Basically I want to extract file names from an xml document in the simulationFiles variable...
I want to use a function from another module as a decorator, but I need it to manipulate the current module's global namespace.
For example, I want to be able to go from this:
class SomeClass:
pass
root = SomeClass
to this:
from othermodule import decorator
@decorator
class Someclass:
pass
Any ideas?
...
this
Application.EventManager.on('Click', function(args) { // event listener, args is JSON
TestAction.getContents(args.node.id, function(result, e) {
console.log(result);
this.add({
title: args.node.id,
html: result
}).show();
});
});
I'm really struggling with scope and anonymou...
Does any language or debug tool have a way to print out the scope chain for examination? Thanks.
...
Is there any way to change a variable while out of scope? I know in general, you cannot, but I'm wondering if there are any tricks or overrides. For example, is there any way to make the following work:
function blah(){
var a = 1
}
a = 2;
alert(blah());
EDIT (for clarification):
The hypothetical scenario would be modifying a variabl...
All custom legacy software needs changing, or so say our users. Sometimes they want a feature or two added and all that is necessary to change a bit of code, add a control, or some other minor upgrade task. Sometimes they want to ditch their error-prone VB5 desktop solution and rewrite the whole thing as a rich Web 2.0 ASP.NET MVC applic...
I have a person object and wants to store it into a global ArrayCollection I have made.
Works great in normal scope:
var s = new ArrayCollection();
s.add(new person("Knud", "Mikkelsen", 35));
The problem is when I want to add people inside my jQuery function "mainFunction".
I can't seem to get it right. I know it's something to do wi...
At the very beginning of the javascript file, I have:
var lbp = {};
lbp.defaults = {
minLength: 40
};
I can successfully alert it afterwards, with:
alert(lbp.defaults.minLength);
But as soon as I put it inside a function, when I alert, I get "Undefined". What gives, and how do I avoid this? Is it absolutely necessary to pass ...
It seems to me that "session" scope is another means to keep objects in session as
using setAttrubute / getAttribute
Correct?
You know, dont know why, it does not work for me.
<bean id="sabreUser" class="util.MyUser" factory-method="getSomeUser" scope="session">
<const args...>
What I see is that after the initialization and initi...
Maybe the question is not self-explanatory, so I will explain it through.
The deal is: I got the variable $conn in the bootstrap class file. I'd like to make it global for every controller so that I just have to call $this->conn in the controller action scope in order to access the data inside. How would I do it?
Thx
...
I always see people in serious projects use :: everywhere, and -> only occasionally in local environment.
I only use -> myself and never end up in situations when I need a static value outside of a class. Am I a bad person?
As I understand, the only situation when -> won't work is when I try following:
class StaticDemo {
privat...
In C++, what is the scope resolution ("order of precedence") for shadowed variable names? I can't seem to find a concise answer online.
For example:
#include <iostream>
int shadowed = 1;
struct Foo
{
Foo() : shadowed(2) {}
void bar(int shadowed = 3)
{
std::cout << shadowed << std::endl;
// What does t...
Can get work the attribute "destroy-method".
First, even if I type non-existing method name into "destroy-method" attribute,
Spring initialization completes fine (already strange!).
Next, when a bean has a "prototype" scope, then I suppose it must be destroyed before the application
is closed. That not happens, it is simply never ca...