function foo() {
console.log(this.a);
}
var obj = {
a: 2,
foo: foo
};
obj.foo();
Regardless of whether
foo()
is initially declared onobj
, or is added as a reference later (as this snippet shows), in neither case is the function really "owned" or "contained" by theobj
object.
However...
the call-site uses the
obj
context to reference the function, so you could say that the obj object "owns" or "contains" the function reference at the time the function is called.
(You don't know JS - this & object prototypes)