Questions tagged as 'closures'

5
answers

How Do Closures Work in JavaScript?

I've always wanted to know how Closures work in JavaScript, I've read some definitions but never quite understood. Could you give me a simple, objective but content explanation?     
asked by 11.01.2014 / 02:43
3
answers

"Disclosure" a closure

I understand the great powers and the great consequences of closures . But suppose I have the following code ... function foo () { var x = 1; function bar () { return x++; } return bar; } ... And I do not want to...
asked by 30.01.2014 / 14:24
2
answers

How to use blocks in Ruby

I'm having a hard time understanding blocks in Ruby. Could someone explain to me why we use it?     
asked by 10.04.2015 / 22:53
1
answer

How to serialize an exception with closure

I'm trying to serialize the exceptions generated by errors to write a log with all the information, but the problem is that some exceptions may come with a closure within the trace and trigger the message below:   Uncaught exception...
asked by 17.11.2014 / 19:16
1
answer

How does an annonymous innerclass arrow an instance private variable?

Given that Java does not actually have closures , but emulates behavior with a technique using inner classes , the following code: class Test{ private int myField; private void doSomething(){ someInstance.setListener(new on...
asked by 28.08.2018 / 03:10
2
answers

Use static Closures or Closures in PHP?

As of PHP 5.4, Closures , when declared within the context of a method of the class (other than static methods), automatically inherits the funções anônimas as a reference of the class that contains it. Example: class StackOver...
asked by 27.01.2015 / 13:07
3
answers

JavaScript Method Overload Function

I'm reading a book called "Secrets of the JavaScript Ninja" and in it, I came across a method overload function. So far so good, I understood what it does, I understand that it makes depending on the amount of parameters passed to the function a...
asked by 02.10.2015 / 18:22
1
answer

What is the benefit of using closures in PHP?

Eg: Why use a closure for this function: We could do the same thing without a closure, but why use this class? public function getTotal($tax) { $total = 0.00; $callback = function ($quantity, $product) use ($tax, &$tota...
asked by 09.07.2014 / 21:32
2
answers

Are Java lambdas equivalent to JavaScript Closures?

I started to study functional programming and I'm a bit confused about these two items. My question is: Is Java lambdas equivalent to JavaScript Closures? If not, what is the difference between them? Thank you.     
asked by 25.05.2017 / 18:22
1
answer

What are variable / anonymous functions and closures? And what are they? How to use?

I think most of the question has already been asked in the title. Being more specific, I wanted real examples of using these techniques and the relationship between them. Note: I read other related answers, but I could not understand 100%....
asked by 31.12.2014 / 16:09