Questions tagged [Closure] (22)

2
answers

The circuit memorizes all or what you need?

Conventionally, we have a function which has local variables and vozvrashaet an object that has methods for working with local variables, which in turn closed. function a(){ let name = 'Ivan'; let surname = "Ivanov"; let arr = [1,2,3,4,5]; return { getName : () =>{ return name} } } obj = a(); console.log (obj.getNam...
Karen.Hell asked April 8th 20 at 17:35
1
answer

How to use recursion in closures in php?

good day dear. Here the magic of php and the question arose how to use recursion in php for example I have an array of multi-level and I want to use recursion in the circuit. the code below in the sandbox trying to start and neproxodim why, do not understand the PHP sandbox<?php $array = array( 'row1' => array( ...
francisca96 asked April 3rd 20 at 19:01
2
answers

Call an instance of another class as argument to Anonymous function gives an error PHP 7?

The three classes you need to render /* Book record: #1 Address: 33 Market street, London, Greater London, EC4 MB5, GB Contact #1: John Doe Contact #2: Anna Baker Book record: #2 Address: 22 Tower Street, SK4 1HV, GB Contact #1: Ms Dane Rovens */ Get the error Fatal error: Uncaught TypeError: Argument 1 passed to Book::cre...
charlene_Nader asked April 2nd 20 at 17:43
2
answers

Where the circuit is used in real projects?

Hi! Recently started learning JS and got to the circuit, I have a couple of questions: Where the circuit is used in real projects?If I did your example with the circuit or it should have been done some other way?In some cases, it is best to declare a pointer function?let createCounter = (start, end) => () => start >...
Jon asked March 31st 20 at 21:10
1
answer

Confused about the short + wrapper, razberemsa?

Friends, is not the first day trying to understand closures, wrappers and call, aply, bind. I understood the meaning of the examples in the tutorial, but when I sit down to write a test job a mess in my head. For example task: Write f-tion of the wrapper, which performs q-tion through the entered period of time. Wrote, lik...
naomie_Volkm asked March 31st 20 at 15:23
4
answers

Why would I want to use this, if there is circuit protection?

Suppose I have two functions for creating the object:// Function No. 1 function square(_a, _b) { let a = _a; let b = _b; let area = 0; let obj = { computeArea: function() { area = a * b; }, getArea: function() { return area; }, get a() { return a; }, set a(value) { a = value; }, get b() { return b; }, set b(valu...
Rosanna.Ryan5 asked March 24th 20 at 14:05
1
answer

The function does not see the correct values state what the problem is, who knows?

Trying to make such functionality on the website: There is a list of the photos if they don't fit in 1 line button again, tap on it to see all the pictures, those that were hidden appear with 2 lines. When onload create variables how many items fit and how much to hide (for example 8 to show and hide 5), and put a listener...
Levi94 asked March 24th 20 at 10:14
3
answers

Is this an example of a circuit, and why or why NOT?

Hello, how do you think, can this feature be counter to the circuit and why or why NOT?let count = 0; function counter() { return count += 1; } console.log(counter()); // 1 console.log(counter()); // 2 console.log(counter()); // 3
Brooks36 asked March 21st 20 at 12:58
1
answer

What circuit is different from currying?

Read about closures and currying and see that both of these concepts are illustrated with the same examples of the type ofdef func(a): def f(b): return a + b return f curr = func(1) print(curr(2)) Please tell me what is the difference between closures and currying. Or is it the same?
Patience_Funk asked March 20th 20 at 11:45
1
answer

JavaScript. How to subscribe to an event in the class constructor?

Good day! JS master recently, had programmed in C#. Can't figure out what I'm doing wrong. Killed a few hours, read about: context, circuit, function switches, bind, call and stuff... but did not understand. There is a class EventEmitter, "nasledujici" from which to obtain the ability to generate custom events. There is a c...
Isabelle asked March 19th 20 at 08:58