r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

6

u/j4afar May 28 '19

Bind and the this keyword

0

u/[deleted] May 28 '19

[deleted]

3

u/PointOneXDeveloper May 28 '19

Defend this statement. I don’t agree at all. Closures exist in many languages and behave more or less the same way in all the languages that support them. The behavior of ‘this’ in JS is, AFAIK, completely unique and can seem like magic when coming from any other language.

‘’’js const myArray = [1,2,3] const mapMyArray = myArray.map ‘’’

The fact that calling ‘myArray.map’ behaves differently from ‘mapMyArray’ is useful in some situations (not this one, it just breaks) and completely core to the language, but it is mostly just weird and dumb. This is the entire reason arrow functions were added.

I’ve used dynamic this binding plenty, ‘Array.prototype.slice.call(myNodeList)’ is a fairly common use case, but if I could, I would have it removed for all the times it causes confusion and makes the language harder to learn.

1

u/PointOneXDeveloper May 28 '19

Lol no GitHub md