scope

jQuery async ajax query and returning value problem (scope, closure)

Hi. Code not working because of async query and variable scope problem. I can't understand how to solve this. Change to $.ajax method with async:false - not an option. I know about closures, but how I can implement it here - don't know. I've seen all topics here about closures in js and jQuery async problems - but still nothing. Help, pl...

How do I scope variables properly in jQuery?

I'm working on a jQuery plugin, but am having some trouble getting my variables properly scoped. Here's an example from my code: (function($) { $.fn.ksana = function(userOptions) { var o = $.extend({}, $.fn.ksana.defaultOptions, userOptions); return this.each(function() { alert(rotate()); // o is not defined }); };...

Globals are bad! But should I use them in this context?

Would setting the $link to my database be one thing that I should use a GLOBAL scope for? In my setting of (lots of functions)...it seems as though having only one variable that is in the global scope would be wise. I am currently using the functions to transfer it back and forth so that way I do not have it in the global scope. But it...

Why can't my function access a variable in an enclosing function?

I know about the LEGB rule. But a simple test of whether a function has read access to variables defined in an enclosing function doesn't seem to actually work. Ie: #!/usr/bin/env python2.4 '''Simple test of Python scoping rules''' def myfunction(): print 'Hope this works: '+myvariable def enclosing(): myvariable = 'ooh this w...

How to get child container reference in View Model

Hello, I´m trying to share a Data Service (Entity Manager) wrapped in a Repository from a ViewModel (called 'AVM') in Module A to a ViewModel (called 'BVM') in Module B, and I can't get this working. We use PRISM/Unity 2.0 This is my scenario: A user may open multiple Customer screens (composite view as mini shell) each with another ...

Bash/shell script - shell output redirection inside a function

function grabSourceFile { cd /tmp/lmpsource wget $1 > $LOG baseName=$(basename $1) tar -xvf $baseName > $LOG cd $baseName } When I call this function The captured output is not going to the log file. The output redirection works fine until I call the function. The $LOG variable is set at the top...

Scope of This JavaScript Variable

I have a question and an issue wrt the code below: My question is what is the scope of the variable loaded here. The reason why i ask this is the onload="if(loaded==1)inittextarea() code is working fine on Firefox and not IE8. Why is this happening? Is there something specific i need to do here? Or is it not a valid practice? <html> <h...

using object in multiple function

Hi. How can i use object from one function in another ? main() { private void button1_click { MyClass object = new MyClass(); object.blabla(); } private void button2_click { // how can i use object from button1_click ?? } } ...

Question on C# Variable Scope vs. Other Languages

First of all, let me say that I've never used C# before, and I don't know about it much. I was studying for my "Programming Languages" exam with Sebesta's "Concepts of Programming Languages 9th ed" book. After I read the following excerpt from "Scope declaration order (on 246th page)", I got a little bit puzzled: "...For example, in...

uses for dynamic scope?

Hi, I've been getting my hands wet with emacs lisp, and one thing that trips me up sometimes is the dynamic scope. Is there much of a future for it? Most languages I know use static scoping (or have moved to static scoping, like Python), and probably because I know it better I tend to prefer it. Are there specific applications/instances ...

Dependency isn't included in my assembly, although scope is "compile"

Edit 4: For the answer to this question see the final comments of the correct answer. Hi! I have the following dependency specified in my project's pom: <dependency> <groupId>org.jboss.client</groupId> <artifactId>jbossall-client</artifactId> <scope>compile</scope> </dependency> My project itself has to be the child of ano...

Referencing environment and scope

All, In any programming language, is the type of referencing environment dependent on the scoping? i.e. a static scoped language would necessarily have static referencing environment? Regards, darkie ...

How do I fix this NameError?

I want to use the value v inside of an instance method on the metaclass of a particular object: v = ParserMap[kind][:validation] # We want to use this value later. s = ParserMap[kind][:specs] const_set(name, lambda { p = Parser.new(&s) # This line starts a new scope... class << p define_method :validate do |opts| v.ca...

Object allocation in C++

char *myfunc() { char *temp = "string"; return temp; } In this piece of code, where does the allocation of the object pointed to by temp happen and what would be its scope? Is this function a valid way to return a char* pointer? ...

Scope of parameter names in Objective C methods

// myClass.h @interface myClass : NSObject { int variable1; } - (int) addOne: (int)variable1; //myClass.m - (int) addOne: (int)variable1{ variable1++; } My question is: will [myClass addOne:aNumber] add 1 to aNumber or will it add 1 to the value of the ivar variable1? ...

Is it possible to restrict how a method can be called in PHP?

Given that my class looks like this: class Methods{ function a(){ return 'a'; } function b(){ $this->a(); } function c(){ $this->a(); } } Is it possible to ensure that function a can only be called from function b? In the above example function c should fail. I could just incl...

JS: I'm not getting the scope

Hi there, I'm trying to modify CouchDB's JS API to work asynchronous, but there is an error I cannot solve: Please find my JS API find at pastebin. If I call (new CouchDB("dbname")).allDocs(function(result) {console.log(result)}) (line 193) I get an error because the okCallback function is not defined in the callback function. I don't...

Are subcontexts in Java separate rows on the stack?

In Java this is the case: public void method() { if (condition) { Object x = ....; } System.out.println(x); // Error: x unavailable } What I'm wondering is this: Is the fact that x is limited to the scope of the if-statement just a feature of the Java compiler, or is x actually removed from the stack after the if-statement? ...

Why does my Workflow Service (4.0) variable go null in a DoWhile Activity?

I have a WF service that I'm trying to setup receive activities to "Subscribe" and "Unsubscribe". I'm using This WF Durable Duplex Tutorial as a basis because my service performs callbacks to clients. Basically, think of it as a chat service. I can make client calls to the two receive activities just fine. What happens is the callback a...

Why do I not see stricter scoping more often?

I've found myself limiting scope fairly often. I find it makes code much clearer, and allows me to reuse variables much more easily. This is especially handy in C where variables must be declared at the start of a new scope. Here is an example of what I mean. { int h = 0; foreach (var item in photos) { ...