Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
will always run code
That's a great explanation, thank you! I've been trying to examine it very closely and everything seems to have become clear, except for the "unexpected" part.
It may be "unexpected", but I would still like to understand it. Why does obj.fn.val becomes changed at all.....
Wait, I think I've finally got it right now while I am writing this. Since
fn
is now 'made' (i think it's a bad word) ofobj.fn
, we can actually usefn.val
, which is by now equal to 1001. When we apply the function itself asthis
, it of course changes the value which used to beobj.fn.val
and is nowfn.val
. I think I had a wrong understanding thatthis
by default refers to the function itself. But it's not the function, it's the context where the function is triggered.Your example is very helpful, thanks again.
Oh, yes. Should be
if (-1 !== index)
Thank you(=
In most cases you don't want to do that. If function relay on
this
in its body (which is equal towindow
unless function defined in object or"use strict";
is used) you probably will encounter some side effects :) It's safer to passnull
and usebind
if you need to keep function's current context.Perhaps an example will make it clear:
I have a question. What if in the Event.prototype.emit we apply not
null
asthis
, but the function itself? Like this:Can someone explain if this can be better or worse in some cases?
if (-1 !== handler)
will always run code