closures

using yield in C# like I would in Ruby

Besides just using yield for iterators in Ruby, I also use it to pass control briefly back to the caller before resuming control in the called method. What I want to do in C# is similar. In a test class, I want to get a connection instance, create another variable instance that uses that connection, then pass the variable to the callin...

javascript - passing additional parameters into an event handler

Hi, I have a javascript object which has some defined variables and attaches some event handlers. I'd like the event handlers to have access to the defined variables. Is there a way to do that ? The event-handlers are within their own local scope so don't have access to the object variables. Is there a way to pass them in without using ...

Queue ExternalInterface calls to Flash Object in UpdatePanel - Needs Improvement?

A Flash (actually Flex) object is created on an ASP.Net page within an Update Panel using a modified version of the embedCallAC_FL_RunContent.js script so it can be written in dynamically. It is re-created with this script with each partial postback to that panel. There are also other Update Panels on the page. With some postbacks (...

Scoping problem with Javascript callback

I am having some trouble getting a callback function to work. Here is my code: SomeObject.prototype.refreshData = function() { var read_obj = new SomeAjaxCall("read_some_data", { }, this.readSuccess, this.readFail); } SomeObject.prototype.readSuccess = function(response) { this.data = response; this.someList = []; for (v...

Java 7 closure syntax

I download the last Java build b96- Feature Complete for testing the new JDK features but I can't figure out which syntax using for testing closures! Can I test it? Which syntax has been approved in the final release? ...

How does this javascript closure work?

Here's some javascript: linkElem.click(function () { var data = linkElem.data(); alert(''+data.mls + ' ' + data.id); }); It works. linkElem is a local variable that I create in a loop inside a function. I assign some data to it with jQuery's .data(). If I did not call .click(), linkElem would be reass...

jQuery/javascript events - prototype event handler

The following code doesn't work as I intuitively expect it to: function MyObject(input) { input.change(this._foo); this.X = undefined; } MyObject.prototype._foo = function() { alert("This code is never called"); // but if it did this.X = true; } var test_input = $("input#xyz"); // a random, existing input var m = MyObj...

Arguments to JavaScript Anonymous Function

for (var i = 0; i < somearray.length; i++) { myclass.foo({'arg1':somearray[i][0]}, function() { console.log(somearray[i][0]); }); } How do I pass somearray or one of its indexes into the anonymous function ? somearray is already in the global scope, but I still get somearray[i] is undefined ...

How to preserve the state of JavaScript closure?

I am working on a migration platform to migrate web applications from a device to another. I am extending it to add the support for preserving JavaScript state. My main task is to create a file representing the current state of the executing application, to transmit it to another device and to reload the state in the destination device....

What do you call a set of Javascript closures that share a common context?

I've been trying to learn closures (in Javascript), which kind of hurts my brain after way too many years with C# and C++. I think I now have a basic understanding, but one thing bothers me: I've visited lots of websites in this Quest for Knowledge, and nowhere have I seen a word (or even a simple two-word phrase) that means "a set of J...

MooTools/JavaScript variable scope

I am trying to make each number displayed clickable. "1" should alert() 80, "2" should produce 60, etc. However, when the alert(adjust) is called, it only shows 0, not the correct numbers. However, if the commented out alert(adjust) is uncommented, it produces the correct number on page load, but not on clicking. I was wondering why t...

How to access a method of a closure's parent object?

I have defined a class named MyClass and I have defined two methods myMethod1 and myMethod2 for it: function MyClass() {} MyClass.prototype.myMethod1 = function() {...}; MyClass.prototype.myMethod2 = function() {...}; Inside myMethod1, I use jQuery and there's a callback closure defined there: MyClass.prototype.myMethod2 = function()...

Perl, "closure" using Hash

I would like to have a subroutine as a member of a hash which is able to have access to other hash members. For example sub setup { %a = ( txt => "hello world", print_hello => sub { print ${txt}; }) return %a } my %obj = setup(); $obj{print_hello}; Ideally this would output "hello world" EDIT Sorry, I failed to spec...

Compatibility between Scala closures and Java 8 closures

After reading some OpenJDK mailinglist entries, it seems that the Oracle developers are currently further removing things from the closure proposal, because earlier design mistakes in the Java language complicate the introduction of the Java closures. Considering that Scala closures are much more powerful than the closures planned for J...

Javascript Closures Explanation

Question: There seem to be many benefits to Closures, but what are the negatives? Additionally, is my understanding of Closures correct? Finally, once closures are created, can they be destroyed? I've been reading a little bit about Javascript Closures. I hope someone a little more knowledgeable will guide my assertions, correcting me...

Javascript Closures - What are the negatives?

Question: There seem to be many benefits to Closures, but what are the negatives (memory leakage? obfuscation problems? bandwidth increasage?)? Additionally, is my understanding of Closures correct? Finally, once closures are created, can they be destroyed? I've been reading a little bit about Javascript Closures. I hope someone a lit...

Javascript Closure and DOM Builder

I am making a DOM builder which I have working succesfully but now I am trying to assign some shorthand functions so that div() -> e("div") Here is my code: //assign these objects to a namespace, defaults to window (function(parent) { /** * Creates string of element * @param tag The element to add * @param options An object of attribu...

Binding class method to event in google maps v3?

In V2 of the Google Maps API, you could bind map events to a class method using the GEvent.bind function: GEvent.bind(this.drag_marker, "dragstart", this, this.start_dragging_route); In the example above pretend that's a link from a prototype.init function, where start_dragging_route is a method inside the class. It appears that the ...

how can python function access its own attributes?

is it possible to access the python function object attributes from within the function scope? e.g. let's have def f(): return SOMETHING f._x = "foo" f() # -> "foo" now, what SOMETHING has to be, if we want to have the _x attribute content "foo" returned? if it's even possible (simply) thanks UPDATE: i'd like the fo...

JavaScript closures inside objects: what alias should have "this" for passing into anonymous function?

We have discussion with our team about next: What correct name should have variable which will be alias for "this" in anonymous function. Simple example: var SomeConstructor = function() { this.someProperty = 'bingo'; this.someMethod = function() { var myObjectAlias = this; $('a').click(function() { ...