Уровень 0 · материалов: 3
В кластер входят документы о технических особенностях и потенциальных ошибках при использовании функций JavaScript, но не входят общие руководства по программированию.
Общие признаки: ошибки при использовании функций, поведение функций в JS, производительность и контекст функций
Группа выше: Ядро JavaScript: объекты, прототипы и контекст
Смысл: The main idea is that arrow functions are a powerful tool for writing concise and readable JavaScript code, but their lack of an internal 'this' context means they cannot replace traditional functions in all scenarios without causing bugs.
Arrow functions offer concise syntax and lexical scoping of 'this', but they should be avoided for object methods and dynamic context binding to prevent debugging and architectural issues.
Смысл: The main idea is to demonstrate how an implicit function call in JavaScript's `map` method can lead to unexpected bugs when the callback function (like `parseInt`) accepts more arguments than the user intends to provide.
The expression `['1', '7', '11'].map(parseInt)` fails because `map` passes the array index as the second argument to `parseInt`, which changes the numerical base (radix) for each element.
Смысл: The main idea is that developers should avoid using immutable update patterns (like spread or concat) inside loop-like functions like .reduce() because it causes severe performance degradation (O(n^2)) without providing any real benefit to code purity or maintainability.
Stop using spread operators or .concat() inside .reduce() because it turns linear performance into quadratic performance by redundantly copying the accumulator every iteration.