A function (often anonymous) bound to the referencing environment in its original lexical scope in such a way that it will still have access to that environment (its variables and other references) if executed outside that scope.

learn more… | top users | synonyms

2
votes
1answer
69 views

Optionally Lazy Parameters

Inspired by Swift's @autoclosure feature, I tried writing a brief C++-14 header that permits "optionally" lazy parameters (by "lazy" I mean ...
4
votes
2answers
131 views

Filtering the attributes for a custom tag

I have function that takes all of the attributes passed to a custom tag, and returns a select subset. I am try to convert the current function, which does not use closures ...
3
votes
2answers
44 views

Configuring fields to be extracted by a data processor

I solved this problem using closures with Perl and I wonder if/how I could/should have done it differently? Background: User creates config file describing properties of some source data file that ...
0
votes
1answer
104 views

Form validation using IIFE and closure [closed]

Problem statement Write an IIFE in which we have to validate the input provided from a form using closures. The form consists of name, email, phone, address in which name, email and phone number ...
0
votes
2answers
93 views

Write an anonymous function validating email address

Problem statement Write an anonymous function which take email address as parameter and returns true/false after validating the input parameter. Objective This assignment will help you ...
2
votes
2answers
132 views

Date formatters, lazily instantiated once

I would like to create two date formatters only on first call. In Objective-C I would use dispatch_once() but now working in Swift. Am I doing it correctly? My code ...
1
vote
0answers
28 views

Web Scraping class schedules

I just want some advice regarding code style and best practices. Also I want to know if I'm using constant declaration and closures properly. This code is used to get the data from here http://...
2
votes
1answer
149 views

Reimplementation of Underscore _.throttle

I've built a function that mimics _.throttle (returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per ...
1
vote
0answers
77 views

Javascript Class System

Warning: The code snippet does run two alerts, just so you know. I wrote a javascript class system with the idea of making declaration simple and clean and instantiation even simpler, along with ...
2
votes
0answers
61 views

groupJoin() in Swift

I have created the following function in Swift for this library I am writing, which joins two arrays on a key (extracted using given closures), and then groups them by key in a ...
3
votes
1answer
481 views

removeAll(closure) in Swift

From this library I wrote, I have created this function in Swift, but I'm not happy with the implementation. Can anyone suggest a better way to do this? I really don't like changing counters inside <...
1
vote
0answers
116 views

JavaScript nesting XMLHttp requests and in a loop

I am new to JavaScript, especially the wonders of async and closures and would like some help on the attached code. It is in a Chrome extension and retrieves a list of users albums with the Picasa Web ...
2
votes
2answers
76 views

Remove list of files from another list of files by their name

In groovy I have a list of files A and also another list of files B. I want to remove all the files from A that have a filename that also occurs in the list of files B. I wrote the following code: <...
2
votes
0answers
89 views

Using my own Optional type with fold method in groovy

I have written an Optional type in groovy roughly based on java8s Optional. I implemented and use a fold method and would like to know if it can be improved. First, ...
3
votes
0answers
100 views

Mangling MP3 collections

I'm writing a little tool for mangling MP3 collections and, as a challenge, I decided to write in in Hy, a dialect of Python that uses Lisp syntax. Like every good developer, I wrote out my list of ...
5
votes
1answer
1k views

Closure as UIControlEvents handler

I'm expanding the functionality of this SO answer. Mainly I'm focusing on: You can add as many handlers as you want. You can remove (i.e. cancel) the handler. You can receive the ...
0
votes
1answer
87 views

Object with highest count in a Groovy list

I have a list of Parcel objects and am trying to write a closure that picks the parcel object with highest count: ...
3
votes
1answer
1k views

Sharing a database connection with multiple modules

I am building what essentially could be viewed as a glorified database wrapper as a Python package, where I'm having several classes and functions spread out into different modules. My current problem ...
5
votes
2answers
209 views

'Countdown' Numbers round - combine numbers arithmetically to reach a target

Countdown is a British gameshow where contestants compete in word and number challenges. During the numbers round, six numbers are chosen semi-randomly and the task is to combine them using addition, ...
0
votes
1answer
81 views

Storing array inside closure

Is storing array values inside of a closure considered to be bad practice? I having been trying to decide if I should just use a standard object with key value pair. This is not the method I am ...
6
votes
1answer
572 views

MVC Model validation callback

I have made a simple MVC framework of my own for my personal website to learn a thing or two about how this whole thing even works. I think I've got the idea, but there's one thing I'm not sure about. ...
3
votes
1answer
52 views

Implementing an “Add Company” section in a project

I'm working on avoiding JavaScript that either directly modifies the DOM a ton, contains a ton of anonymous functions, or is encapsulated in giant ...
1
vote
1answer
229 views

Node.js callback closure/scope

Is it a bad idea to use the notfound callback like this? If so, why not? (bad scope/closure? I'm a noob node.js dev.) Is it a bad idea to use the ...
5
votes
1answer
246 views

Closures in C#, necessary or not?

I've written JavaScript for a while, but lately I've been writing a lot of C#. I wanted to write a method that could take the column name of a DataTable and return ...
2
votes
2answers
302 views

Deeper abstracting of code into functions

I created a quiz using the module pattern. My code is as follows: ...
2
votes
1answer
188 views

Is my JavaScript OOP style correct?

I have done the following code for testing a web-service. Is my style correct for using OOP in JavaScript? ...
4
votes
2answers
93 views

Writing a user's profile image to disk using nested Node.JS closures

I am writing non-blocking code as it should be in Node.JS. If I want run function A after B I do it using callback. But I find this style guide: Use closures, but don't nest them. Otherwise your ...
1
vote
1answer
223 views

JavaScript binding loss with setTimeout

My current task is to extend some JavaScript of a framework we are using. A pop-up should slide in, instead of just appear in the middle of the window. So I have overridden one of the framework's ...
3
votes
1answer
348 views

Correctly dealing with closures and modularity in Javascript

The code below is designed to deal with this situation: There is a Battle environment with Characters; these Characters obviously have certain characteristics and abilities, and they need to be ...
1
vote
3answers
364 views

Cleanest way to close over a counter in CoffeeScript

I haven't spent too much time with CoffeeScript and am trying to have a simple counter: ...
0
votes
3answers
150 views

Processing image blocks using a task runner

This code works, but I'm sure it isn't written according to "best practices" for closures. On the other hand, at least it's intuitive to me... the taskRunner object runs functions on setTimeout, so ...
4
votes
2answers
520 views

JavaScript closure: code trivia to keep the event handler separate

Note: This was originally posted at SO, and as per the recommendation moving to this form. In my effort to learn JS on the backdrop of SVG development, I got lot of help from SO so far. The answer ...