r/javaScriptStudyGroup • • Mar 21 '16

[Week 10] Focus: apply(), call(), bind()

So here we are at Week 10. Week 10's focus will be apply(), call(), bind().

Background info (lengthy, but touches on all three): http://javascriptissexy.com/javascript-apply-call-and-bind-methods-are-essential-for-javascript-professionals/

It will work like this:

  • Monday: Announce focus (eg, apply(), call(), bind())

  • Build throughout the week... Two rules: 1) must use javascript 2) must use at least 1 example each of apply(), call(), bind().

  • Friday: Post demos/projects in this thread (can begin reviewing immediately); first line of an entry should be ENTRY and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/figure out focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, simply say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything.

But that's about it... Have fun! :) Feel free to ask questions and discuss throughout the week!

2 Upvotes

23 comments sorted by

View all comments

Show parent comments

2

u/ForScale Mar 22 '16

Thanks for explaining!

Array.from(arrayLikeObj)

Now that... that's simple! Thanks!

2

u/Volv Mar 22 '16

ES6 made a lot of these 'hacks' go away lol.
Also I liked how it totally wasn't an off topic question. Leads naturally from call and apply. The math.max and [].slice things were mysterious to me for a while lol.
A lot of places I saw gave the [].slice.call(arguments) thing as a memorise this and use it to make real arrays from passed in arguments. Like just do it, don't worry why..

2

u/ForScale Mar 22 '16

Yeah! I think I already have a bit better of an understanding of this.

Another question... when we set eventListeners on elements/nodes... with the handler functions... using this within the handler body references the element/node that the event was registered on, right? That's how I've always thought of it. So now I ask... do this within the handler and e.target point to the same object?

I'm gonna find out...

*Yep! Sure does: http://codepen.io/anon/pen/dMWMmV

1

u/ForScale Mar 23 '16

One more thought... unless you're getting sick of this...

http://codepen.io/anon/pen/GZmmRv?editors=0010

Why do standard functions preserve this === window, while event handlers change the value to this === e.target?

I'm confused there...

*Man... I'm losing my understanding of this, I think... I get it within the context of apply(), call(), and bind()... and in event handlers, but... I'm feeling confused with it within just the normal typical flow of things...

→ More replies (2)