There are four ways of calling a function:
- Function invocation:
f(p1, p2)
- Method invocation:
obj.f(p1, p2)
- Apply or Call invocation:
f.apply(obj, [p1, p2])
, f.call(obj, p1, p2)
- Constructor invocation:
new f(p1, p2)
In all these cases, f
is just a reference (pointer) to a function object (an object with a [[Call]]
internal property). What makes it behave different in all these cases is the way the function is called, and that matters a lot.
So, f
is just a reference to the getElementById
object, there's no difference between document.getElementById
and someOtherHTMLElement.getElementById
; the function doesn't hold back a reference to the object that references it.
If you want to bind a certain "owner" object, use the bind
method:
var f = document.getElementById.bind(document);