closures

Referring to "this" in a parent closure in javascript

I want to do this in Javascript: function Z( f ) { f(); } function A() { this.b = function() { Z( function () { this.c() } ); } this.c = function() { alert('hello world!'); } } var foo = new A(); foo.b(); It can be accomplished this way: function Z( f ) { f(); } function A() { var self = this; this.b =...

Closures in Python

I have seen & used nested functions in Python. They match the definition of a closure. It is not closure simply because it is not used by external world? UPDATE: I was reading about closures & it got me thinking about this concept with respect to Python. A little bit of search got me to the article someone in the comments pointed to. B...

Get Value Outside of db.transaction Scope in Web SQL DB

Pretty sure the answer to this question is "closures" but I'm having a hard time getting it right. Given the following: var total = 0; db.readTransaction(function (tx) { tx.executeSql('SELECT COUNT(id) AS mytotal FROM sometable', [], function (tx, results) { total =results.rows.item(0).mytotal; conso...

How to include an already documented method in jsdoc-toolkit?

I have a JavaScript singleton object created with closure method: /** * This is the singleton. * * @namespace window.Something.Singleton */ window.Something.Singleton = (function() { /** * Foo method. * * @return {String} this method always returns with <code>bar</code> */ function _foo() { return "bar"; } /** ...

Self-Invoking Functions in JavaScript

Hi, What's the difference between these functions? Thanks for reply! Function #1 var myQuery = (function() { (...) })(); Function #2 var myQuery = (function() { (...) }); ...

PHP closures and implicit global variable scope

Is there a way that one can implicitly declare top-level variables as global for use in closures? For example, if working with code such as this: $a = 0; //A TOP-LEVEL VARIABLE Alpha::create('myAlpha') ->bind(DataSingleton::getInstance() ->query('c') ) ->addBeta('myBeta', function($obj){ $obj->bind(DataSing...

VB.Net - "With" and Closures don't mix

Just thought I'd share this in case anyone else has run into this. I did something similar today and it took me a while to figure out why this was causing a problem at runtime. This code: Public Class foo Public bar As String = "blah" End Class Public Sub DoInline() Dim o As New foo Dim f As Func(Of String) With o f = Func...

PHP Objects and Closures

I've been asking a few questions on this topic recently, so I feel it appropriate to link up the associated question(s). http://stackoverflow.com/questions/4054424/php-closures-and-implicit-global-variable-scope I've got a set of classes that use closures as in the example below (keep in mind I quickly punched together this example for...