Questions tagged as 'closures'

1
answer

Use closure as a function return

I need to use a variable of a closure as a function return to which this closure is nested. How can I do this? response must be the return of ajaxRequest() : function ajaxRequest(type, url) { const ajax = new XM...
asked by 21.12.2016 / 20:42
1
answer

Scope of PHP variable

So, I've been banging my head for some time now with a basic scope question, but I could not figure out why. In the function below, I'm trying to access a position of the object that is running at the time of Foreach, though it is giving the...
asked by 22.11.2018 / 13:16
3
answers

What is the advantage of using function (window, document, undefined)

I've noticed for a long time that many libraries are using something like: (function(window, document, undefined){ //exemplo de script console.log(window, document); })(window, document); or (function(window, document, undefined){...
asked by 28.12.2014 / 18:23
3
answers

Execute php code inside a variable

Good evening personal You can run this: <?php $variavel = 'foreach($v1 as $v2){echo $v2;};'; echo $variavel; ?> Or is there anyway to run a class inside a variable (a function I know it has): <?php $variavel = 'class teste(...
asked by 19.06.2015 / 02:27
1
answer

Is it possible to serialize closures in PHP? [duplicate]

Is it possible to serialize closures in PHP (even if it is not natively)? Because PHP generates a Fatal Error when trying to do so: $func = function ($a, $b) { return $a + $b; }; serialize($func); This generates:   ...
asked by 31.07.2015 / 17:16
1
answer

Difference between closures and functions

Closures is a function in Groovy? Is there any difference between them?     
asked by 05.03.2018 / 18:58
1
answer

Recursions in closures

# -*- coding: utf-8 -*- def memoize(limit, *, message = 'Limit exceded'): count = 0 def inner(func): cache = {} def wrapped(number): nonlocal count if count < limit: if number no...
asked by 05.04.2018 / 15:13
2
answers

Is it possible for a Closure (Swift) to capture reference of the instance of the object that executes it?

I'm passing a closure to an object's property, and within the closure I'd need to reference the instance of the object that will execute the closure. Example: typealias validator : ()->Bool class Field : NSObject { var name...
asked by 21.11.2016 / 14:23
1
answer

How to guarantee the type of value returned by a closure?

I can perform the requests with Alamofire, but I saw that it is not possible to use return within the scope of success. After a search, I saw that the solution is to use a closure pattern, to get the value of the request when it is finished,...
asked by 24.04.2016 / 06:48