FUNCTION OVERLOADING IN JAVASCRIPT

Опубликовано: 14 Октябрь 2020
на канале: Joel Codes
5,402
146

JavaScript may not support Function Overloading, but we can simulate the behavior.

In other languages, an overloaded function can be created by adding another function with the same name. This can't be done in JavaScript because the 2nd function will overwrite the 1st function.

One method of simulation this behavior is to detect the function argument types.

NOTE: As stated below in the comments, the code does not consider null as an argument and will error if null is received. To prevent this error use this if statement to also check for null.

```
if (typeof x === 'object' && x != null)
```

Subscribe to my Newsletter: https://joel.net/newsletter
Article: https://joel.net/simulated-function-o...

0:05 - What is Function Overloading?
0:24 - Example of Expected Behavior
1:38 - Simulate an Overloaded Function
2:37 - Recommended Alternative to Overloading
3:19 - Say Hello to Dumpling!


На этой странице сайта вы можете посмотреть видео онлайн FUNCTION OVERLOADING IN JAVASCRIPT длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Joel Codes 14 Октябрь 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 5,402 раз и оно понравилось 146 зрителям. Приятного просмотра!