scope

JavaScript context

var User = { Name: "Some Name", Age: 26, Show: function() { alert("Age= "+this.Age)}; }; function Test(fn) { fn(); } Test(User.Show); =============== Alert shown by code is "Age= Undefined". I understand as User.Show function is called from inside of Test(), refers 'this' of 'Test()' function rather than 'User'...

JQuery callback question

Hi, I'm trying to assign a different number to different callback functions in jquery. for (i=o;i<types.length;i++) { $('#ajax'+types[i]+'Div').html('Loading...').load('searchAjax.php','new=u',function () { $(this).find('select').change( function() { AjaxDiv(i); } ) } ); } Everytime I run this section of code, i is 5 for each c...

Haskell scoping in nested function definitions using where

I have a problem with Haskell's scoping in where definitions. When I have the following function f, where I want to pass the x to the locally defined function f1 without explicitely using it as a parameter, I get an error saying that the type of x is incompatible with the one in the output of f1, although it should be the same: f :: Eq...

scope of local variables of a function in C

I have heard about the following scenario right when I started programming in C. "Trying to access from outside, a functions local variable will result in error (or garbage value). Since the stack gets cleared off when we return from the function" But my below code sample prints a value of 50. I am compiling the code with latest GCC c...

Overriding a Rails default_scope

If I have an ActiveRecord::Base model with a default-scope: class Foo < ActiveRecord::Base default_scope :conditions => ["bar = ?",bar] end Is there any way to do a Foo.find without using the default_scope conditions? In other words, can you override a default scope? I would have thought that using 'default' in the name would sug...

Define constraints on the context in which as class is instantiated

I wonder if there's a way to define a class in such a way that instances of it will never be members of another class (only local variables), or the other way round - only members but never local. Is there any way in which a class can dictate the scope of it's prospective instances? ...

msgStore was not declared in this scope (XCode)

I'm implementing callback routines for external static C++ library to be used in Objective-C project. Now I have trouble moving data between callback and normal routines. As you can see below my "msgStore" is defined as part of MyMessage class and can be used within class routines such as init(). However attempting same from callback rou...

Scope of class help

Hi I'm trying to reuse some code i was pointed to earlier to run a 3rd party .exe inside of a my winform the code i was given was via Mr. Greg Young public class Native { [DllImport("user32.dll", SetLastError = true)] private static extern uint SetParent(IntPtr hWndChild, IntPtr hWndNewParent); public static v...

javascript scope issue

Code snippet as follows: $(this).parents('td:first').next().find('option').customizeMenu('myMenu2'); This works,but : var listener = function(){ $(this).parents('td:first').next().find('option').customizeMenu('myMenu2'); }; listener(); is not working,why and how to fix it? ...

default scope in older rails versions

afternoon all. i am working on a project written on rails 2.1 in newer versions we can use a rather cool method to create a default scope like so default_scope :order => 'title ASC' how can the same/similar effect be achieved without upgrading the rails version? ...

C++ static member functions and their scope

I have two questions. In C++, a static member function has direct access to a public non-static data member defined in the same class? False In C++, a non-static member function has direct access to a private static data member defined in the same class? True My note say false for the first question and true for the second one. I jus...

Problem with class template specialisations

I'm trying to port some code from VC9 to G++, however Ive run into a problem with template specialisations apparently not being allowed for class members. The following code is an example of these errors for the getValue specialisations of the class methods. In all cases the error is "error: explicit specialization in non-namespace scop...

node.js callback getting unexpected value for variable

I have a for loop, and inside it a variable is assigned with var. Also inside the loop a method is called which requires a callback. Inside the callback function I'm using the variable from the loop. I would expect that it's value, inside the callback function, would be the same as it was outside the callback during that iteration of the...

Variable scope js - return initial assignment instead of changed

Have next script: function clicker(){ var linkId = "[id*=" + "link]"; var butnId='initial'; $j(linkId).click(function(){ var postfix = $j(this).attr('id').substr(4); butnId = '#' + 'butn' + postfix; }); return butnId; } Function output is 'initial' value. How to return actual value of variable butnId,after it...

Calling a function by a string in JavaScript and staying in scope

Hi, I've been playing around and searching a bit, but I can't figure this out. I have a pseudo private function within a JavaScript object that needs to get called via eval (because the name of the function is built dynamically). However, the function is hidden from the global scope by a closure and I cannot figure out how to reference i...

Why is this explicit scope resolution necessary?

Setup: class A { public: void a() {} }; class B { public: void b() {} }; class C: public A, public B { public: void c() {} }; What (I thought) I should be able to do: C* foo = new C(); foo->b(); And I get the following linker error from GCC: `... undefined reference to 'C::b(void)'` If I use explicit scope re...

Store javascript variables in array

I am sure someone has gone over this but I have had no luck finding some results. I want to know what is the fastest way to maintain a proper variable scope. Here is some example jquery code I wrote this morning. var oSignup = { nTopMargin: null, oBody: $("div#body"), oSignup: $("div#newsletter_signup"), oSignupBtn: $("d...

Finding correct scope of an Object for a callback

I'm working on writing a tweening class in as2 that has a callback variable and I can't seem to find a good way to get the scope without specifically passing in a scope variable as well. This tweening class needs to work in classes as well as on the timeline. Here's what my codes looks like right now. params.scope[ params.onComplete ]( ...

Why can't the VBA Me keyword access private procedures in its own module?

I just discovered that the Me keyword cannot access private procedures even when they are inside its own class model. Take the following code in Class1: Private Sub Message() Debug.Print "Some private procedure." End Sub Public Sub DoSomething() Me.Message End Sub This code instantiates an instance of the class: Sub TestCla...

Populate ruby Array1 with Array2 String element if and only if Array2 element matches Hash value(not key).

I have a ruby hash: VALS = { :one => "One", :two => "Two" } and an Array: array2 = ["hello", "world", "One"] Question: How can I populate a new array1 so that it only pulls in any values in array2 that match exactly the values in VALS? For example, I have tried: array2.each_with_index do |e,i| array1 << e if VALS[i] ~= e end Alon...