Questions tagged [anonymous-function]

Anonymous functions use a block of code as a value, defining it as an inline function without a name.

2121 questions
27
votes
2 answers

How to use $this in closure in php

I have function like this: class Service { function delete_user($username) { ... $sessions = $this->config->sessions; $this->config->sessions = array_filter($sessions, function($session) use ($this){ return…
jcubic
  • 61,973
  • 54
  • 229
  • 402
27
votes
3 answers

How do you declare a Func with an anonymous return type?

I need to be able to do this: var getHed = () => { // do stuff return new { Property1 = value, Property2 = value2, etc...}; }; var anonymousClass = getHed(); But I get an error which indicates I need to explicitly declare getHed. How do I…
Price Jones
  • 1,948
  • 1
  • 24
  • 40
27
votes
1 answer

Anonymous function vs normal function

Just out of interest, are there any speed/functionality differences between function foo(bar) { alert("foo" + bar); } and var foo = function(bar) { alert("foo" + bar); };
Bluefire
  • 13,519
  • 24
  • 74
  • 118
25
votes
3 answers

Clojure: returning a vector from an anonymous function

I wrote a small anonymous function to be used with a map call. The function returns a vector containing a column name and column value from a SQL result set query. Here is the function (input is the column name): (fn [name] [(keyword name)…
Ralph
  • 31,584
  • 38
  • 145
  • 282
25
votes
2 answers

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 =…
asdasd
  • 261
  • 1
  • 3
  • 3
25
votes
1 answer

How to pass anonymous functions as parameters in Rust?

I've been playing around with Rust the past week. I can't seem to figure out how to pass a function that is defined as a parameter when calling the method, and haven't come across any documentation that shows them being used in that fashion. Is it…
nathansizemore
  • 3,028
  • 7
  • 39
  • 63
25
votes
3 answers

Google Tag Manager isn't loading javascript, error message "anonymous function"

I have installed Google Tag Manager on my website, and am using it to load some Javascript onto my site. However, GTM is no longer loading, my Javascript isn't loading, and the error code is not very helpful. Here is the GTM code on my website: