JavaScript call() apply() bind() Methods In 90 Seconds #JavaScriptJanuary
Watch the entire #JavaScriptJanuary series from the beginning!
In JavaScript the call(), apply(), and bind() methods can be used to assign an object to the “this” keyword.
The first argument is the object being assigned. Then we can pass in more arguments. These will then be used by the function.
The apply() method is similar to the call() method. The only difference is that the call() method takes arguments separately and the apply() method takes arguments as an array. So when working with arrays you would want to use apply().
There are other interesting things we can do with apply(). For instance, JavaScript arrays do not have a max() method. So if we have an array of numbers and we want to get the maximum value we could use apply().
Since we are not assigning anything to the “this” keyword, so we just set that to null then pass in our array.
The bind() method creates a new bound function, which wraps the original function object. So we are essentially creating a new function bound to the object. Then we call the function along with our arguments.
I’ll be releasing a new video every day in January! Stay tuned..
_____________________________________
📚 Learn to CODE in just a FEW months here:
Treehouse Discount Code: https://treehouse.7eer.net/codeSTACKr
_____________________________________
🛠️ Tools I use:
🟠 Theme: https://marketplace.visualstudio.com/items?itemName=codestackr.codestackr-theme
🟠 Font: STACKr Code (Exclusive to my VS Code Course – https://vsCodeHero.com)
🟠 SuperHero Extension Pack: https://marketplace.visualstudio.com/items?itemName=codeSTACKr.superhero-extensions
🚢 Deploy for FREE on Vercel: https://vercel.com/ambassadors/codestackr
_____________________________________
💖 Show support!
PayPal: https://paypal.me/codeSTACKr
_____________________________________
Watch Next:
Web Development – Beginners Roadmap (2020) – https://youtu.be/iogabydg2y0
Playlist: Web Development For Beginners – https://www.youtube.com/watch?v=Ez4yHS2dsN8&list=PLkwxH9e_vrAJ0WbEsFA9W3I1W-g_BTsbt
_____________________________________
Connect With Me:
Website: http://www.codestackr.com
Twitter: https://twitter.com/codeSTACKr
Instagram: https://instagram.com/codeSTACKr/
Facebook: https://facebook.com/codeSTACKr
_____________________________________
** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.
#JavaScriptJanuary #31Days31Videos #codeSTACKr
source