anonymous-function

ExtJS listeners: anonymous function parameters

I grabbed this code form some book I've bumped on the InternetS... sm: new Ext.grid.RowSelectionModel({ singleSelect: true, listeners: { rowselect: { fn: function(sm,index,record) { Ext.Msg.alert('You Selected',record.data.title); } } } }); now, sm is shorthand for selection...

Binding anonymous functions all over the place.

I generally write code that looks like this (but with many more handlers). $(document).ready(function() { $("#next").click(function() { doStuff(); }); $("#prev").click(function() { doSomeOtherStuff(); }); $("#link").hover(function() { doSomeTotallyOtherStuff(); }); }); Is this the bes...

Why are functions in JavaScript set to global variables instead of plain functions?

I am wondering if anyone knows why some people define global variables that are set to functions vs just defining a global function name. For example: var foo = function() { alert('hello!'); } instead of function foo() { alert('hello!'); } Wouldn't the second method be better since there is a chance something might overwrite the f...

javascript: Using the current for-loop counter-value inside a function() { }?

Hi, on a website i want to do this: (simplified) myHandlers = new Array(); for(var i = 0; i < 7; i++) { myHandlers.push(new Handler({ handlerName: 'myHandler'+i, // works, e.g. ->myHandler1, 2, 3 etc. handlerFunc: function(bla) { /*...*/ alert(i); } // doesn't work,all return 7 } } I could set the counter as another attrib...

Are anonymous functions a bad practice in javascript?

I was reading that using anonymous functions in javascript is bad practice, because it can make debugging a pain, but I haven't seen this for myself. Are anonymous functions in JavaScript really bad practice and, if so, why? ...

Javascript Function instance is automatically casted to object and can't be called anymore

Hi, I'm working with a fairly complex Javascript program wich, at a given point, returns some nested anonymous functions. Sometimes, when I try to "apply" one of such anonymous functions ("f" in this example)... f.apply (this.context, args) ...I get an "f.apply is not a function" error. It's weird, because alert(f) displays the fun...

Return anonymous getter function in Flex / Actionscript?

Getter functions allow obj.meth syntax instead of obj.meth(), I'd like to create an anonymous one of these to return from another function. function get ():Object { } is invalid syntax. I don't suppose Flex offers an easy way to get this functionality, if it's even possible? ...

Mapping factory methods with anonymous functions/delegates using Dictionary for faster lookup?

Currently, I have a static factory method like this: public static Book Create(BookCode code) { if (code == BookCode.Harry) return new Book(BookResource.Harry); if (code == BookCode.Julian) return new Book(BookResource.Julian); // etc. } The reason I don't cache them in any way is because BookResource is sensitive to cultu...

How do I use an anonymous function within a class method in Python (closure) ?

class Test: def somemethod(self): def write(): print 'hello' write() x = Test() x.somemethod() write() is a function that will be used several times through somemethod(). somemethod() is the only function within the class that will require it's use so it seems silly to define it outside of somemethod(...

Anonymous functions legality

Both Eclipse and NetBeans throw errors about the use of anonymous functions. The error in NetBeans says The language feature not compatible with PHP version indicated in project settings The code is working but the IDEs don't seem to like it. Should I be worried? ...

Anonymous functions pre PHP 5.3.0

Is there an alternative to anonymous functions for versions of PHP previous to 5.3.0? ...

Problem with setTimeout and anonymous function in Javascript

Why this doesn't work in Firebug console: function(s,e) { setTimeout(function(){grvClosingDocs.Refresh();CBPDocFlow.PerformCallback();},100) } While this does: setTimeout(function(){grvClosingDocs.Refresh();CBPDocFlow.PerformCallback();},100) ...

Are procedural variable and anonymous function equivalent when there's no outer context?

I understand that there are special actions to maintaining the lifetime of a outer variable when it was mentioned inside an anonymous procedure. But when the anonymous procedure doesn't use outer variables, will it generate the same assembly call as the good old general procedure. In other words, will the internals of the anonymous funct...

How do I pass an anonymous subroutines when calling a Perl subroutine?

mysub gets a subroutine reference as its first argument. Can I simply call mysub(sub{some subroutine body here}) ? I.e. define an anonymous subroutine right at the call? Is the syntax OK (is it really a reference to sub that is passed)? ...

Should I encapsulate blocks of functionality in anonymous JavaScript functions?

My intuition is that it's a good idea to encapsulate blocks of code in anonymous functions like this: (function() { var aVar; aVar.func = function() { alert('ronk'); }; aVar.mem = 5; })(); Because I'm not going to need aVar again, so I assume that the garbage collector will then delete aVar when it goes out of scope. Is this rig...

Converting a PHP anonymous function to non-anonymous

Hi, I asked a related question before I lost my login id - http://stackoverflow.com/questions/3723748/php-version-5-2-14-parse-error-syntax-error-unexpected-t-function-expecting - but this is the "entire" problem. I'm having a hard time figuring out how to convert this function (got from somewhere on SO) to work with PHP 5.2.14 (which ...

Is there a difference between (function() {...}()); and (function() {...})(); ?

Possible Duplicate: Location of parenthesis for auto-executing anonymous JavaScript functions? Sometimes I see: (function() { ... }()); and sometimes I see: (function() { ... })(); I see both forms with and without arguments. They both execute the anonymous function. Is there a difference between the two forms? Are t...

Converting code with Anonymous functions to PHP 5.2

Hi, I have some PHP 5.3 code which builds an array to be passed to a view. This is the code I have. # Select all this users links. $data = $this->link_model->select_user_id($this->user->id); if (count($data) > 0) { # Process the data into the table format. $table = array ( 'properties' => array ( ...

Ruby: Can lambda function parameters have default values?

I want to do something similar to this: def creator() return lambda { |arg1, arg2 = nil| puts arg1 if(arg2 != nil) puts arg2 end } end test = creator() test('lol') test('lol', 'rofl') I get a few syntax errors: test.rb:2: syntax error re...

How/when is this anonymous function invoked?

Hi. I'm new to javascript and I am looking through some Raphael demo code. I'm confused by how this is working... if (R) { (function (dx, dy, R, value) { var color = "hsb(" + [(1 - R / max) * .5, 1, .75] + ")"; ... From what I can see this is declaring an anonymous function which takes 4 arguments. How is this function inv...