I'm trying to load external SWFs in a for loop, and I have this problem that is really eating me: In the event handler I need to know the filename of the SWF that was loaded, but I can't obtain this. The code below shows what I'm trying to do.
Does anybody have any idea?
function loadManySWFs(arrayOfFileNames:Array)
{
for(var i=0;...
I have an empty .js file with this code in it:
Cart.CheckoutNow = {
...
}
// Alias
if (typeof(CheckoutNow) === 'undefined') {
CheckoutNow = Cart.CheckoutNow;
}
else {
alert('CheckoutNow is already a variable in window.');
}
How can I have the // Alias code appear at the top of the page, but have it execute after Cart.Checko...
Closures in a loop are causing me problems. I think I have to make another function that returns a function to solve the problem, but I can't get it to work with my jQuery code.
Here is the basic problem in a simplified form:
function foo(val) {
alert(val);
}
for (var i = 0; i < 3; i++) {
$('#button'+i).click(function(){
foo(i...
If I make a class against a local namespace, how exactly does it work? For instance:
>>> def foo():
... i = 1
... class bar(object):
... j = i
... return bar
...
>>> dis(foo)
2 0 LOAD_CONST 1 (1)
3 STORE_DEREF 0 (i)
3 6 LOAD_CONST 2...
Is it possible to simulate closures in PHP 5.2.x not using globals? I could think of a way that would pass the desired variables as extra parameters to the closure but that just doesn't feel like best practice.
Any ideas?
...
What is the current state of spec for Java closure?
1.
In the proposed Java closure spec, would we be able to
create an array or collection of closures?
If so, would this syntax be possible?
{int x, int y => boolean b}[] comparisonSwitch = {
{int i, int j => return i>j},
{int i, int j => return j<i},
{int i, int j => return j==...
I am coming from a functional-programming background at the moment, so forgive me if I do not understand closures in C#.
I have the following code to dynamically generate Buttons that get anonymous event handlers:
for (int i = 0; i < 7; i++)
{
Button newButton = new Button();
newButton.Text = "Click me!";
newButton.Click ...
I noticed in JQuery that the following code structure is used
(function(){var l=this,g,y=l.jQuery,p=l.$,...})()
Which seems to create a function, and call it.
What is the benefit of taking this approach versus having the contents of the function inline?
...
Let me explain, this is about displaying class source code in IDEs. I have always only one class per file. A class is declared like this in the file mod1.js:
MYGLOB.MOD1.ClassXy = function () {
//constructor, do somothing
}
MYGLOB.MOD1.ClassXy.prototype.memberfunc1 = function () {
//member function 1, do somothing
}
(There are ma...
I'm working on a bit of code where I'm attempting to hide some private variables inside closures. The thing is the environment is fairly constrained in terms of memory, so I'm also concerned with keeping the overall footprint of the classes low.
What is the impact of using closures to hide private instance variables and methods when com...
Taking the following code, Resharper tells me that voicesSoFar and voicesNeededMaximum cause "access to a modified closure". I read about these but what puzzles me here is that Resharper suggests fixing this by extracting the variables to right before the LINQ query. But that is where they are already!
Resharper stops complaining if I m...
In Java, I know that it is possible to do something like this:
public class Greeter {
public void greetEventually() {
final String greeting = "Hello!";
Job j = new Job() {
public void run() {
System.out.println(greeting);
}
};
j.schedule();
}
}
This would ...
Hey folks,
I made a utility debug class in a C# game I'm working on to be able to monitor and watch values of properties. Goes like this:
public static class Monitor
{
private static List<object> monitoredObjects;
public static void Initialize()
{
monitoredObjects = new List<object>();
}
public static void Watch(object ...
Hay guys, I'm making a simple preload function
(function($) {
$.fn.preload = function(settings) {
var config = {
before: function(){ return; },
end: function(){ return; },
after: function(a){ return; }
};
if (settings) $.extend(config, settings);
var limit = this.length - 1;
var counter...
If block is a closure, why this code does not work? And how to make it work?
def R(arg)
Class.new do
def foo
puts arg
end
end
end
class A < R("Hello!")
end
A.new.foo #throws undefined local variable or method `arg' for #<A:0x2840538>
...
Not having them used them all that much I'm not quite sure all that lambdas/blocks can be used for (other than map/collect/do/lightweight local function syntax). If some people could post some interesting but somewhat understandable examples (with explanation).
preferred languages for examples: python, smalltalk, haskell
...
Recently I started playing around with Python and I came around something peculiar in the way closures work. Consider the following code:
adders= [0,1,2,3]
for i in [0,1,2,3]:
adders[i]=lambda a: i+a
print adders[1](3)
It builds a simple array of functions that take a single input and return that input added by a number. The funct...
Hello, I was toying (read: learning) around with Javascript and came across something to my understanding, seems very odd. It has to do with closures and a reference that seems to 'loose' its importance to the browser.
The browser I am using is Chromium 5.0.307.7.
Anyway, here's some code:
HTMLElement.prototype.writeInSteps = function...
Is there a standard way of dealing with the interaction between separate compilation and different kinds of closure conversion when compiling higher-order function calls?
I know of three function-like constructs that are distinctly compiled in most programming languages: closures, (top-level) functions, and C++-style function objects. S...
I am having trouble with JS closures:
// arg: an array of strings. each string is a mentioned user.
// fills in the list of mentioned users. Click on a mentioned user's name causes the page to load that user's info.
function fillInMentioned(mentions) {
var mentionList = document.getElementById("mention-list");
mentionList.innerH...