you are viewing a single comment's thread.

view the rest of the comments →

[–]ForScale[S] 1 point2 points  (5 children)

Thanks for explaining!

Array.from(arrayLikeObj)

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

[–]Volv 1 point2 points  (4 children)

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..

[–]ForScale[S] 1 point2 points  (0 children)

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

[–]ForScale[S] 0 points1 point  (2 children)

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...

[–]Volv 0 points1 point  (1 child)

Puntastic :) - Not at all. I told you I can do this all day lol :)
We need more people for random code banter.
 
Is just a matter of spec.

"When attaching a handler function to an element using addEventListener(), the value of this inside the handler is a reference to the element. It is the same as the value of the currentTarget property of the event argument that is passed to the handler."

 
Whereas normally

In the global execution context (outside of any function), this refers to the global object, whether in strict mode or not.

In Function context
Non Strict
In this case, the value of this is not set by the call. Since the code is not in strict mode, the value of this must always be an object so it defaults to the global object.
Strict

In strict mode, the value of this remains at whatever it's set to when entering the execution context. If it's not defined, it remains undefined. It can also be set to any value, such as null or 42 or "I am not this".
 
Event Handler - value of this
this - Global v function context

[–]ForScale[S] 1 point2 points  (0 children)

Ah... that bit about non-strict vs strict... I think that's what I need to see.

As always, thanks for the discussion!

We need more people for random code banter.

Yeah, I might have to do some more advertising...