scope

Functions scope at a file level in C#/.NET?

I have many many functions (100+ estimated) and more then half are only needed in the file its defined. Is there a way to define functions so it scope is at a file level? ...

Custom Object calling Methods with setTimeout loses scope

I'm having an issue with building a Javascript object, and calling methods within that object using setTimeout. I've tried various workarounds, but always during the second part of my loop the scope becomes the window object rather than my custom object. Warning: I'm pretty new at javascript. my code: $(function() { slide1 = Object...

What is the scope of a defaulted parameter in Python?

When you define a function in Python with an array parameter, what is the scope of that parameter? This example is taken from the Python tutorial: def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) Prints: [1] [1, 2] [1, 2, 3] I'm not quite sure if I understand what's happening here. Does this mean that...

C# scoping operator

back in school, we wrote a compiler where curly braces had the default behavior of executing all expressions, and returning the last value... so you could write something like: int foo = { printf("bar"); 1 }; Is there something equivalent in C#? For instance, if I want to write a lambda function that has a side effect. The point les...

In ECMAScript5, what's the scope of "use strict"?

What scope does the strict mode pragma have in ECMAScript5? "use strict"; I'd like to do this (mainly because JSLint doesn't complain about it): "use strict"; (function () { // my stuff here... }()); But I'm not sure if that would break other code or not. I know that I can do this, which will scope the pragma to the function... ...

PHP isset($this) and using the same object method in a static and object context

I'm working on a class which needs to be accessible via static function calls as well as object methods. One thing I have found is that I'm duplicating logic across multiple functions. Simplified example: class Configurable{ protected $configurations = array(); protected static $static_configurations = array(); public fu...

Distinguishing closure and local variables

A local function in the closure declares a variable with the same name which exists in the closure. So, how could we access closure's variable from the local function? function closure() { var xVar; function func1() { var xVar; // how to distinguish local and closure scopes. return xVar; } re...

How can I prevent a name error error in python?

When I run my program core.py (http://pastebin.com/kbzbBUYd) it returns: File "core.py", line 47, in texto core.mail(numbersendlist, messagetext) NameError: global name 'core' is not defined Can anyone tell me what is going on and how I can stop this error? If it helps, the "import carrier" line in core.py refers to carrier.py (ht...

Are python functions threadsafe? (Particularly this one?)

Before answering, please understand I do NOT want you to do the work for me. I would rather appreciate a worded answer as to why my (possibly theoretical) problem exists, and an explanation of the process to go about fixing it. I find it harder to learn properly when someone just does the work for me. Thank you in advance. I have thi...

simply access members of other namespaces

I am using the famous module pattern for creating namespaces however its cumbersome to write ns1.ns2.member to access a member from ns3(ns1.ns2.ns3). I do not like using a shortcut var(_ns2=ns1.ns2) for this purpose also with statement considered harmfull so what is the better to handle this problem? is it possible to combine scope of na...

i cant get my javascript eventlistener to work properly

this has got me stumped, ive tried lots of different things, but cant get this to work. can anyone help? no matter what i try i cant get the click eventlistener on the link to fire. the code is in a greasemonkey script. i believe i have to use the closure method to be able to refer to the function dropit in the greasemonkey script, as it...

Javascript scoping - parents siblings

In the example below I'm trying to access the parents sibling. Is there a better way than what I've come up with, what gives? Broken: var funkyness = function(){ var some_obj = { foo: function() { alert('bar'); }, 'wrapper' : { 'OK': function() { // I want to acces...

Javascript: Calling a function written in an anonymous function from String with the function's names withoout eval?

Update2: What I really wanted to ask was already argued in a different page. Please check the following entry. (Thanks to BobS.) http://stackoverflow.com/questions/598878/how-can-i-access-local-scope-dynamically-in-javascript Hello. I've started using jQuery and am wondering how to call functions in an anonymous function dynamically ...

Does filehandle get closed automatically in Python after it goes out of scope?

If I do the following, does filehandle get closed automatically as it goes out of scope in Python: def read_contents(file_path): return file(file_path).read() If it doesn't, how can I write this function to close the scope automatically? ...

Scope of controls in asp.net content blocks

Just ran into some interesting problem. I've separated a panel from a asp:Content block to another. In the original asp:Content block still resides a asp:FormView with childs, which references multiple ObjectDataSources. These ObjectDataSource are defined in the same asp:Content block. The separated panel has child controls which are us...

Is it possible to access outer local variable in PHP?

Is it possible to access outer local varialbe in a PHP sub-function? In below code, I want to access variable $l in inner function bar. Declaring $l as global $l in bar doesn't work. function foo() { $l = "xyz"; function bar() { echo $l; } bar(); } foo(); ...

Flash Action Script 3 function scope

go_btn.addEventListener(MouseEvent.CLICK, getPlayerName); var playerName; function getPlayerName(e:MouseEvent) { playerName = playerName_txt.text; } trace(playerName); Hi, is there any way to have this work. I want to update a variable outside the scope of the function. Thanks ...

How to find Junit tests that are using a given Java method directly or indirectly

Assume there are Java project and Junit project in an Eclipse workspace. And All the unit tests are located in the Junit project and dependent on the application Java project. When making changes to a Java method, I need to find the unit tests that are using the method directly or indirectly, so that I can run the corresponding tests loc...

Using a singleton database class in functions and multiple scripts(PHP) - best use methods

I have a singleton db connection which I get with: $dbConnect = myDatabase::getInstance(); which is easy enough. My question is what is the least rhetorical and legitimate way of using this connection in functions and classes? It seems silly to have to declare the variable global, pass it into every single function, and/or recrea...

MySql scoping problem with correlated subqueries

Hi, I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT DISTINCT category_en FROM categories c WHERE id IN (SELECT DISTINCT category_id FROM m3allems_to_categories m2c WHERE m3allem_id = 37) ) cS ) categories ,(SELECT GRO...