This question already has an answer here: Access variables from parent scope in anonymous PHP function 1 answer There is an example in the Cookbook: $query = $cities->find() ->where(function ($exp, $q) { return $exp->notIn('country_id', ['AFG', '
I read a number of articles about the javascript scope chain and I thought I had a decent understanding of it. However, a very simple exercise made me realize I do not yet understand it at all. I created the following code. function foo () { var b =
Say I have a class as follows in a header file: class A { public: void foo(); } The function foo needs to call another "helper" function named bar. Bar isn't needed anywhere else other than inside foo. Should it be defined statically outside the
i am trying to set a title with the function below and then call another function so i can render the view but after I cannot see the title. here is my code: snippet from another file: $indexPage = new View(); $indexPage->setPageTitle('This is the ti
I am contributing one of the ruby on rails application over GitHub where I faced the following scenario: I am having following models which I want to convert to make polymorphic: class Comment < ActiveRecord::Base belongs_to :team belongs_to :project
In the following program, the user is supposed to enter a String (name of a City) and the program should return the index of the corresponding City in the array. But I get an error, in the subroutine indexCities the following message: "nameCity canno
This question already has an answer here: Why doesn't C# allow me to use the same variable name in different scopes? 5 answers Not sure if this is because the C# compiler is extra picky, but I try to do this in C#: public static void Main() { bool re
I walked on something weird while doing some JS code today. I wanted to execute an object's method if the property existed, and some other function if it didn't. Feeling a little bit fancy, I wrote something like: var obj = { method: function(){ cons
I have created two object in session scope like this @SessionAttributes({"userObj","simpleValue"}) in my controller. I am adding a user object and String at these variables in my controller like this: modelAndView.addObject("userO
I am writing a Rails 4.2 app with models user, notecard, tag and tagging (for the m-2-m relationship). A tag can have multiple notecards and a notecard can have multiple tags. A card belongs to a user and a tag DOESN'T belong to a user. How can I sco
I am trying to create my own Font Chooser class in another separate class from the file where I have my main class (a JFrame application), and I would like to access to the textArea object of the main JFrame, in order to modify its font properties, b
I am new to javascript and while I was practicing scope I tried the following code: var il = "inner"; var o ="outer"; var of = function(){ console.log(o + " " + il); o = "baher"; var il = "ander"; console.
The following ERD includes the classes involved in the question. Here are the code of the 3 main classes (Monitoring, Link and Story). class Monitoring < ActiveRecord::Base belongs_to :company has_many :keywords, through: :monitoring_keywords has_man
What is the scope of variables in Mule expression components, and how does that relate to flow variables? I had a flow with a set-variable and was surprised to see that the value was being overwritten by an assignment in an expression-component. For
This question already has an answer here: Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors? 3 answers <?php echo '<pre>'; error_reporting(E_ALL); $pid = '129'; $famili
I have this code snippet: <ul> <li ng-repeat="message in messages"> <button ng-click="send()">Send</button> </li> </ul> $scope.send = function(){ // not working (message undefined) alert($scope.messa
If I want to share an object between multiple methods in a controller, is it wrong to create an instance var? E.g. class MyController { def index() { def user = verifyUserLogin() [messages:getMessages(user)] } private verifyUserLogin() { ... return u
I can't seem to make apply function access/modify a variable that is declared outside... what gives? x = data.frame(age=c(11,12,13), weight=c(100,105,110)) x testme <- function(df) { i <- 0 apply(df, 1, function(x) { age <- x[1] weight <- x[2]
A long shot, but putting it out there -- looking for a way to provide privacy based on a common relative package scope. So, for example, is there a way to use private[foo] for packages com.company1.foo and com.company2.foo where each package will hav
If I do something like // global scope function stuff() { // local scope var a = new SomeHugeMemoryHog(); } // a doesn't exist down here, but what happened to the memory from the "stuff" scope? Will I create a memory leak if I don't set a = null
I am creating an object inside of an enclosure. Also in the enclosure are private properties that the object's functions can access - and this works as expected. My issue: I want others to be able to extend my object with functions of their own (func
I have a few questions about the INTENT of variables within a subroutine in Fortran. For example, several weeks ago, I posted a question about a different Fortran topic (In Fortran 90, what is a good way to write an array to a text file, row-wise?),
I am learning memory management in C++ and I don't get the why only some of the destructors are called when leaving scope. In the code below, only obj1 destructor is called when myfunc ends, not for the dynamically allocated obj2. int myfunc (cl1 *oa
I'm new here and am not 100% sure how to ask this question so I'll just dive right in. Should I be using import statements at the beginning of every function I write that import all of the various modules/functions I need for that function's scope? i
I know there are ways to make helpers available to controllers, but that this is generally bad form. How should the following be re-worked to avoid this? I have a Contacts helper called "fullname" that combines a contact's first and last names.
I'm using the jquery ui drag/drop code. Upon a drop a getJSON request gets executed to check the new data and update the database. This works fine, until my backend return an error, because I can't cancel the drop from within the anonymous function.
I find myself doing something like this constantly to pull GET args into vars: some_var = self.request.get('some_var', None) other_var = self.request.get('other_var', None) if None in [some_var, other_var]: logging.error("some arg was missing in &quo
Suppose you have this pseudo-code do_something(); function do_something(){ print "I am saying hello."; } Why do some programming languages require the call to do_something() to appear below the function declaration in order for the code to run?P
Variable scope in JS is confusing the hell out of me. In follwing code, if i use the setClient public method to set a clientID i can then access the value from inside the track method using the getClient method. I cannot however access the value of t
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