scope

Access javascript variables from calling scope.

I am trying to define a function which can access variables which are in the scope of the function that is calling it. ( I am attempting to build a string formatter that is prettier than "a" + b, and more terse than String.format("a{0}",b). So I can get SF("a{b}"), and I don't know if it is possible ) so function magic(str) { re...

Is it possible to release a variable in c#?

I'm just curious... Is it possible to release a variable in c#? What I mean is, can you do something like this: ... string x = "billy bob"; //release variable x somehow string x = "some other string"; //release variable x somehow int x = 329; ... ... so basically you are declaring the variable multiple times in the same scope. ...

Finding Functions Defined in a with: Block

Here's some code from Richard Jones' Blog: with gui.vertical: text = gui.label('hello!') items = gui.selection(['one', 'two', 'three']) with gui.button('click me!'): def on_click(): text.value = items.value text.foreground = red My question is: how the heck did he do this? How can the conte...

Where to put Application scope components in Winforms?

Where do you store application scoped components in your winforms apps? I see that I can create a descendant of Component in my application. I could then drag and drop the components that I want to share among the forms in my project. Is this the best practice for shared access to components (non-visual controls)? In Delphi, we had a Dat...

Import functions from table as local functions in Lua

I want to achieve this (import functions from util table as local values): function blah () local x = util.x local y = util.y ... end without having to reference each function explicitly, e.g. something like: function blah() for name,f in util do ??? end end Unfortunately there is no local table that I could set the wa...

jQuery scope problem

I am trying to create a sort of generic xml parser, like this: Part 1: An object with filter is created: var product = { holder : { id: '', title: '', text : '', price: '' }, filter : { id: '', test: function( elementHolder ) { if( elementHolder.id == product.filter.id ) { return true; ...

Adobe AIR - What is the proper method for using an EventListener on a newly created window?

I'm very new to AIR development, and have just started seriously building my first simply application. I'd like to open a new window to prompt the user for desired settings upon first run. In testing the new window and detecting its closed state, I've done the following (some jQuery code included): The following code is used to open t...

Anonymous methods, scope, and serialization.

Let's say I have the following code: public class Foo { private int x; private int y; public Bar CreateBar() { return new Bar(x, () => y); } } [Serializable] public class Bar { private int a; private Func<int> b; public Bar(int a, Func<int> b) { this.a = a; this.b = b; }...

What is 'this' before an object is instantiated in js?

I don't understand the following: var x = function() { this.foo="foo"; return function() { this.bar = "bar"; return foo+bar; }; }(); // returns inner alert(x()); // 'foobar', so both 'this' variables are set alert(x.bar); // undefined - but wasn't it used correctly? alert(new x().bar); // ok, works My assumption was that a def...

python scooping and recursion

I am struck in a small recursive code. I have printed output and it prints fine but when I try to put a counter to actually count my answers, it gives me scooping errors. total = 0 def foo(me, t): if t<0: return if t==0: total = total+1 return for i in range(1, me+1): total = total+1 return foo(i, t-...

Hashtable in java is giving me the last stored value, but not the right value

Sorry this is kinda long, but I needed to get the right scenario. This outputs all C's, why?? thanks in advance import java.util.Hashtable; public class Main { public static ContainsTheHash containsthehash = new ContainsTheHash(); public static StoresValues storesvalues = new StoresValues(); public static GetsValuesAn...

PHP Scope and Class Instance Interaction

It seems as though different instances of a class can know about each others' private member variables. I have provided some code that attempts to showcase my issue, and I will try to explain it. We have a class with a private member variable, $hidden. modifyPrivateMember sets the value of $hidden to 3. accessPrivateMember takes an Obj...

How to implement scoped iostream formatting?

I'd like to scope-limit the effect of I/O stream formatting in C++, so that I can do something like this: std::cout << std::hex << ... if (some_condition) { scoped_iofmt localized(std::cout); std::cout << std::oct << ... } // outside the block, we're now back to hex so that base, precision, fill, etc. are restored to their previo...

C# Making a delegate available to a class

I would like to make a delegate available to an entire class. The point of this is to allow a called method from an external class' backgroundWorker to continually report back through all of it's methods (ExternalClass.Run(); calls ExternalClass.Method2(); ExternalClass.Method3(); etc and they all need to send several progress reports. I...

do included javascript files have access to global variables in the parent document?

Imagine some code something like this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; <HTML> <HEAD> <TITLE>BLAH</TITLE> <script language='Javascript' type='text/javascript'> var ScriptVersionReqd='1.0'; </script> <script language='JavaScript' type='text/jav...

Perl variable scope question

So I have a Perl class. It has a sort() method, and I want it to be more or less identical to the built-in sort() function: $object->sort(sub ($$) { $_[0] <=> $_[1] }); But I can't do: $object->sort(sub { $a <=> $b }); Because of scoping. But the List::Util module does this with reduce(). I looked at the List::Util module, and they...

Javascript Member Functions Out of Scope

I have a class that creates an anchor object. When the user clicks on the anchor I want it to run a function from the parent class. function n() { var make = function() { ... var a = document.createElement('a'); a.innerHTML = 'Add'; //this next line does not work, it returns the error: //"this.add_but...

Why is my for loop stopping after one iteration?

Racking my brains on this one. I have the code below: the first stages of a JavaScript game. All the objects are well-defined and I'm using jQuery for DOM interaction. The puzzle is created with the following JS code: var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}"); Howev...

Scope of javascript variable declared inline

Here are the problem scripts: This is from the HTML file: <script type="text/javascript"> var devices_record = "some string"; </script> <script type="text/javascript" src="/js/foo.js"></script> This is from foo.js: function bar () { devices_record = "assign new string"; } The error report by HttpFox is that devices_ record...

C# - Location of Using Statements

One thing I have noticed a lot of back and forth on is where using statements should be placed in a C# code file- whether its in the outermost scope or inside a namespace. I understand that the location of the using statement affects the scope of the references within that file, but what I don't understand is why, in most cases, someone ...