3 года назад
Functions in JavaScript
A function is a reusable block of code that groups together a sequence of statements to perform a specific task. One way to create a function is by using a function declaration. Just like how a variable declaration binds a value to a variable name, a function declaration binds a function to a name, or an identifier. A function declaration does not ask the code inside the function body to run, it just declares the existence of the function. The code inside a function body runs, or executes, only when the function is called...
3 года назад
JavaScript. Методы: call, apply, bind
В этой статье мы разобрали как работает this. Если вы пропустили данный материал, рекомендую изучить сначала его. Теперь мы рассмотрим варианты, где контекст т.е. this можно принудительно привязать к функции. Для этого используются следующие методы: 1. call 2. apply 3. bind Рассмотрим эти методы более детально. Метод call Метод call позволяет указать объект, на который будет ссылаться this во время вызова Функции. Метод call применяется к функции, в параметре получает объект. При этом функция выполняется, и внутри нее this становится равным переданному объекту...