I'm reading someone's code and I see the following:
this.device_name.changes().onValue(this.changeName.bind(this))
From what I understand, onValue
takes a callback function, and that function is this.changeName.bind(this))
. Correct me if I'm wrong:
- The default value of
this
in a function call refers the object with which the function was called upon. - The
.bind(someObject)
method causes the function'sthis
to refer tosomeObject
instead, when the function gets executed.
Knowing this (heh), this.changeName.bind(this)
seems redundant: the default value for this
when calling this.changeName
will be the same this
that is passed in the bind
parameter.
So! Can the function be safely refactored to simply this.changeName
with no differences in behavior?