The Journey of #100DaysOfCode (wassim_taleb)

๐ƒ๐š๐ฒ ๐Ÿ : ๐๐จ๐ซ๐ฆ๐š๐ฅ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ ๐ฏ๐ฌ. ๐€๐ซ๐ซ๐จ๐ฐ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ ๐ข๐ง ๐‰๐š๐ฏ๐š๐’๐œ๐ซ๐ข๐ฉ๐ญ

The key difference between the two functions lies in their handling of the this keyword.

โ†’ ๐๐จ๐ซ๐ฆ๐š๐ฅ ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ have their own this context, which changes depending on how they are called (whether globally or locally). This can cause problems that you might not be aware of.

โ†’ ๐€๐ซ๐ซ๐จ๐ฐ ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ, on the other hand, inherit this from the surrounding scope normally, making them particularly useful for maintaining context while calling them. Besides, it offers cleaner and easier code to read.

2 Likes