scope

IPython with own scope?

Hi all, I encountered a problem with the scope variables have when IPython is invoked at the end of a python script. All functions I call in the script itself can modify variables, which will subsequently be used by other functions. If I call the same functions in ipython, the scripted ones can access the changed variables but variables...

PHP: Variable scope in OOP?

Hi everybody, Here's my code: class Manual extends controller { function Manual(){ parent::Controller(); $myVar = 'blablabla'; } function doStuff(){ echo $myVar; // Doesn't work. } } I've tried various methods to make it work, but I've can't get my head around it. What can I do? Thanks ...

Extjs How to initialize new elements when extending - without losing scope

I am trying to get better at extending the classes of Extjs, and my evolvement have lead me to this problem: I have extended an Ext.Panel and I want my extension to have a bottom toolbar with one button as default. myPanel = Ext.extend(Ext.Panel, { method: function () { return 'response!'; }, bbar: new Ext.Toolbar(...

Struts2 scope interceptor problem

Hello fellow geeks, I have a problem with Struts2's ScopeInterceptor: after the action that is set to be the end of a workflow is executed the interceptor doesn't clear the session for the element that was set at the beginning. This is how I have set up my classes and struts.xml: struts.xml <package name="build" extends="base-package...

How to specify the default scope in Spring's applicationContext.xml to request scope?

I want to make all beans request scoped by default, however the Spring documentation says that the default scope is Singleton. (sections 3.4.1 and 3.4.2 http://static.springsource.org/spring/docs/2.5.x/reference/beans.html) I want to declare the default scope to be request scoped. This is the closest thing I have found so far -- it's ...

jquery callback function scope

when i use jquery to create an element(a div, for example) in a callback function, it doesn't allow me to manipulate the newly created element outside the callback function, how can I get around this? here is the example: $.get('menu.xml',function(data){ //create a new element with an ID called "#newElement" }) //I can't select the ...

Update variables inside the jQuery $(document).ready() base scope?

I'm trying to find a way to minimize the number of Selector look-ups. My issue is that I have a variable defined with base $(document).ready() that needs to be updated inside functions nested inside $(document).ready() Consider this example (EDIT: I updated it to be more explanatory) <script> //var $current_page = $home_page; **<--I ...

MOOTOOLS variable scope

I'm using mootools: I can't figure out how to use a variable when using an addEvent. I want to use a for next loop to set values in a loop: for (x=0;x<num;x++){ var onclickText = 'function (){onclick="addPageMoveEvent('+x+'"); }'; $('pageNum'+x).addEvent('click', onclickText); } > I've search forums but not found any help. Any help...

Ruby variable scope question -- alternatives to class-level variables for class_eval?

I have a question about best practices for Ruby variable scope using class_eval. In the below code snippet, in the class_eval block, the local variables first and second are undefined. def parent_method(opts={}) first = opts[:percent] second = (10 * first).to_i SecondClass.class_eval do def second_method; return {:...

Is Ruby's "binding" the same as Scope Chain?

Ruby's eval() can be like def showblock(&block) puts eval("i * 3", block) end where block is the block passed into the function. Instead of a block, a binding object can be passed in as well. Is the binding object the same as what is called the "scope chain" that is mentioned a lot when Javascript closure is discussed? ...

C++ Raii and stack unwinding

hello (I modified the original question to be more meaningful) With respect to return statement, are Raii object destroyed before/after/between return statement? for example size_t advance() { boost::lock_guard<boost::mutex> lock(mutex_); return value_++; // is lock destroyed after increment? } thank you ...

Restricting access to some elements in Javascript

Hi everyone, For a project that will let developers add their own Javascript applications, I need to limit scope of Javascript to a certain div. For example, each developer will have access to their own div. <div id="md5_of_a_salt_and_app_id"> <script> /* This area should not be able to modify window element * or ...

javascript anonymous function scope

I have the following anonymous function: (function() { var a = 1; var b = 2; function f1() { } function f2() { } // this => window object! // externalFunction(this); })(); function externalFunction(pointer) { // pointer.f1(); => fail! } I need to call external function from this anonymous function and pass it's pointer to...

Function and declaring a local variable

Just having an conversation with collegue at work how to declare a variables. For me I already decided which style I prefer, but maybe I wrong. "C" style - all variable at the begining of function. If you want to know data type of variable, just look at the begining of function. bool Foo() { PARAM* pParam = NULL; bool rc; ...

Is there a way to break out of the default_scope when using has_many?

I have a tree-like model where in all situations but one, I want to scope the results to only return the roots. class Licence < ActiveRecord::Base default_scope :conditions => { :parent_licence_id, nil } belongs_to :parent_licence, :class_name => 'Licence' has_many :nested_licences, :class_name => 'Licence', :foreign_k...

Jquery - How do you pass a variable into a function to use?

Hi, I am stumped by a problem which i'd assume is a common Jquery occurence, but i've no idea how to fix! I have 5 variables - var pubtimed var toolstimed var newstimed var mylinkstimed var partnerstimed Which are used to store on and off states. I then have a script that checks cookies for recent states and updates the va...

Javascript singleton: access outer attribute from inner function

// i = inner, o = outer, f=function, a=attribute var singleton = function() { var iF = function() { return this.oA; // returns undefined } return { oF: function() { this.oA = true; return iF(); }, oA: false }; }(); singleton.oF(); If singleton were a class (as in a class-based language), shouldn't I be able to acce...

Fixing Scope Issue With Variable Of Type Var

In the code below, I need to set "Variable1" to an arbitrary value so I don't get into scope issues further below. What is the best arbitrary value for a variable of type var, or is there a better way to avoid the scope issue I'm having? var Variable1; if(Something == 0) { //DB = DatabaseObject Variable1 = from a in DB...

How do I make this anonymous Javascript function reference the right variable?

Example: var o = {}; for(var i = 0; i < 5; i++) { o[i] = function () { console.log(i); }; } o[3](); When I call o3, it will always display 5 on the console, even if I call o0, o4, or any one of those. It will always display 5 because that's the last value i had. How do I make it display the value of i when the anonymous fun...

Sharepoint 2007 search slowdown (using custom scopes)

Is there really a slowdown issue when using custom scopes in searching for contents in Sharepoint 2007? How do you resolve this? I experience the slowdown every after 3 or 4 tries (so the first tries work just fine). I'm using a custom masterpage but the same issue is encountered in OOB portals (using default masterpage). ...