ga-wdi-boston / js-function-context-this

Other
0 stars 126 forks source link

WAT #24

Closed payne-chris-r closed 7 years ago

payne-chris-r commented 8 years ago
function goBoom() {
    console.log(this);
};

let deathstar = {};
goBoom.call(deathstar);
// this === deathstar

Context: this refers to the passed object. Here you would say "the object receives the method".

@gaand -- Why isn't it " Here you would say the method call receives the object as an argument"?

gaand commented 8 years ago

call is a method on Function.prototype that invokes the function, in this case goBoom, on which it is called with the object passed set to this, in this case deathstar. So, it's equivalent to the following:

const goBoom = function () {
    console.log(this);
};

let deathstar = { goBoom };
deathstar.goBoom();
// this === deathstar

but without actually making goBoom a property of deathstar.

payne-chris-r commented 8 years ago

Ok. I understand, but I think that sentence might create more confusion than it removes...

gaand commented 8 years ago

I'm not arguing that point, and I'd be happy to see a different explanation (maybe something based on my response to your query?) I'm just trying to address your WAT

raq929 commented 8 years ago

I would read this as, "Call the function goBoom with deathstar as the context (this)"

Are we trying to clarify the README?

jrhorn424 commented 8 years ago

I'm more inclined toward @rts's wording than @payne-chris-r's at the moment.

gaand commented 8 years ago

@raq929's wording seems quite clear to me 🤖 .

payne-chris-r commented 8 years ago

Good. Than we're all in agreement. I like @rts' wording better too

jrhorn424 commented 8 years ago

raq929 commented 7 years ago

This accidentally got reverted. 😞

payne-chris-r commented 7 years ago

I saw that! Noooo. #everythingIsNoLongerAwesome. But it can be again! #nextIteration.

jrhorn424 commented 7 years ago

How did this reversion happen?

raq929 commented 7 years ago

My fault; I copied and pasted some of Chris's code from his training branch (or something like that), and I copied too much.

On Tue, Dec 6, 2016, 4:00 PM Jeffrey Horn notifications@github.com wrote:

How did this reversion happen?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ga-wdi-boston/js-function-context-this/issues/24#issuecomment-265270726, or mute the thread https://github.com/notifications/unsubscribe-auth/ANRw2IOKKsN5dd0nnGfnQzkaZwYQi2h3ks5rFc0HgaJpZM4KQSPq .