Answer the question
In order to leave comments, you need to log in
In what order do you write JavaScript code?
As far as I know, in order to understand the code, it is not recommended to use anonymous functions. But in what sequence is it correct to write functions and include them in a loop? Is it more correct to first write all the functions at the beginning of the document, and then initialize them, or is it possible to create a function above each cycle and then include it in the cycle?
From personal experience, it is very inconvenient when a function is described at the beginning of a document, but is included in the middle or towards the end.
Answer the question
In order to leave comments, you need to log in
The code should read like a story - from top to bottom. Each function must be followed by functions of the next level of abstraction. This allows you to read the code by successively descending the levels of abstraction as you read the list of functions.
You ask the right questions...
First: Sequence in Java Script is not important, but you need to understand the flow of execution. For example:
function Mun(a){ return a };
( function(a){ console.log(a+' пошел'); } )( Mun('Первый') )
/* Результат сразу же - Первый пошел */
/* Мы создали функцию и выполнили её */
function MunGo(a){ console.log(a+' ушел'); };
function Mun(a){ return 'Не '+a };
MunGo(Mun('Первый'));
/* Выдаст - Не Первый ушел. */
... /* продолжая верхний пример*/
( function(a) {
var Mun = function(a){ return a+' и третий'};
MunGo ( Mun(a) ); /* Выдаст - Второй и третий ушел */
}
) ( 'Второй');
MunGo( Mun ('Второй') ); /* Выдаст - Не Второй ушел */
I'm writing any code from the beginning to the end of this very code.
"write all the functions at the beginning of the document, and then initialize them" - how is that? Does JS have function initialization?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question