scope

Property Scope (Iphone)

Hello All. I am having trouble accessing a declared property and I think I am missing something fundamental about the nature of properties and perhaps view controllers. Here's what I'm doing so far: declaring a property "myPhone" in a root view controller called RootViewController. grabbing a phone number from a modally presented peo...

Inject into private, package or public field or provide a setter?

I see many Java examples using dependency injection with private fields without a public setter like this: public SomeClass { @Inject private SomeResource resource; } But that is a bad idea when the injection should be performed manually for example in unit tests. There are several possibilities to solve this: add a public sett...

JavaScript, MooTools and variable/object scope

I might be using the wrong patterns here, but if I am, I hope someone can correct me! I have an object which represents a user's workspace and, in response to a server action, it clones a div, changes some of its properties, positions it on the workspace, makes it draggable and adds an onComplete action. This action is intended to call ...

Preserving a reference to "this" in JavaScript prototype functions

I'm just getting into using prototypal JavaScript and I'm having trouble figuring out how to preserve a this reference to the main object from inside a prototype function when the scope changes. Let me illustrate what I mean (I'm using jQuery here): MyClass = function() { this.element = $('#element'); this.myValue = 'something'; ...

Link click function of parent object to redirect to href

I'm feeling so dumb asking this question, but I can't figure out a clean way to write this... Heres the HTML <li> <a class='link_parent' href='#'>Test</a> </li> I want the click function of the parent LI to redirect the href of the a with .link_parent... so... $('a.link_parent').each(function() { $(this).parent().click(function()...

rails named_scope and :source

I am a beginner in Rails, Can we use :source with named scope? I am able to use it with has_many and other associations Thanks Mark ...

Variables going beyond scope?

my code: <html> <head> <script type="text/JavaScript" src="jquery-1.3.2.min.js"></script> <script type="text/JavaScript" src="jquery.center.js"></script> <script type="text/JavaScript"> $(document).ready(function(){ $('a').click(function(){ popup_AskYN("Want me to tell you what 1 + 1 is?",function(){ ...

What does Out Of Scope mean?

Hello, I have received an error that indicates that "savedNumberDict" is Out Of Scope. I am not quite sure where to look for a solution. Any suggestions? The code is below that I am using. Thanks. - (void)applicationDidFinishLaunching:(UIApplication*) application { self.savedNumber = [[NSUserDefaults standardUserDefaults]objectFor...

Javascript Scope and local variables

I'm really not sure if this is possible in Javascript. Here's my function: var tree = function(name, callback) { if (this.name) { this.name.push(name) print(this.name) } else { this.name = [] } callback() } I'd like to use it as follows and print out the heirarchy: tree("john", function() { tree("geoff", functio...

Django templatetag scope forcing me to do extra queries

The problem is that if I call a templatetag into a block and it fills me a variiable with the usual context[varname]=something, then if I need that variable into another block, I have to call the templatetag again. This for me means extra db queries, which is really something I'm trying to avoid. This templatetag is called in a base tem...

c++ using declaration, scope and access control

Typically the 'using' declaration is used to bring into scope some member functions of base classes that would otherwise be hidden. From that point of view it is only a mechanism for making accessible information more convenient to use. However: the 'using' declaration can also be used to change access constraints (not only for functions...

Easiest way to set a PHP CONSTANT in 1 file and access it everywhere?

I have asked similar questions before but here is a full demo example code. In PHP how can I access a Constant value that is set in a config file and then included into every page, Including CLASS FILES? I realize this is some sort of scope issue so what is the best way to access this constant inside my class file below without passi...

Scope Guard in C

I would like to use scope guard in C in order to do profiling. I would like to know how much time I spend in a function. Here is what I do: int function() { tic(); ... do stuff ... if (something) { toc(); return 0; } toc(); return 1; } I need to place a toc statement each time I exit the function. I would li...

Inheriting ThreadStatic values to implement dynamic scoping in C#/.NET in multithreaded context

Is there a way to make newly-spawned threads inherit the values of ThreadStatic state (or something like it) on their parent threads? I would like to use this (or something like it) to implement "dynamically scoped" special variables that contain operation/task context information to use for tracking/logging, etc. Is this a reasonable ...

Java, executing a method when object's scope ends

I've an object with a certain state. The object is passed around and it's state is temporarly altered. Something like: public void doSomething(MyObject obj) { obj.saveState(); obj.changeState(...); obj.use(); obj.loadState(); } In C++ it's possible to use the scope of an object to run some code when constructing and di...

Delphi - Declaring in class or not?

Just recently, probably because I've been maintaining some old code, I've started to look at how / why I do things. As you do. Most of my Delphi programming has been picked up in house, or from examples scattered across the web or manuals. And in some things are done just because "that's how I do it" What I'm currently wondering abou...

C scope question

Is the following code valid int main(){ int * a = 0; if ( !a ) { int b[500]; a = b; } //do something with a, //has the array a is //pointing too gone out //of scope and garbage //or is it still fine? } ...

Wordpress loop inside of function = fatal error

I have my Wordpress blog on blog.mysite.com, and a totally different site (built in my framework) at www.mysite.com. I know if the blog and another site are on the same server, and have correct permissions, I can use the following to "syndicate" my blogs to the non-blog site with: define('WP_USE_THEMES', false); require('/var/www/vhos...

Setting anonymous function scope of 'this' in jQuery utility / ajax methods

As noted in this blog post you can set the scope of this in an anonymous function in Javascript. Is there a more elegant way of scoping this in the anonymous function call on success of the AJAX request (i.e. not using that)? For example: var Foo = { bar: function(id) { var that = this; $.ajax({ url: "www.somedomain...

Pylons: free module-level variables?

Not even sure if module-level is correct here, but... I have a Pylons project and within the model component I have a global variable, doc, in __init__.py that I want to use from different Query objects. (doc is a Document handle on an XML file that I am using as a fake DB.) My question is, when does __init__.py's scope end? Currently I...