Regular functions belong to the class that defines these functions and the same object that invokes the function is passed to the function as the fist parameter and function handle it with this keyword;
When an object is created from a class it contains only a set of properties and there is no function in the object. And the functions belong to the class.
however, how is a function called by an object?
Consider the following code.
var obj = {
p1: 'property 1',
func1 () {
return this.p1
},
func2 (param) {
return this.p1 + param
}
}
And also call functions by obj object
obj.func1 ();
obj.func2 ('A');
In fact, functions at runtime look like the following
var obj = {
p1: 'property 1',
func1 (this) {
return this.p1
},
func2 (this, param) {
return this.p1 + param
}
}
func1 (obj);
func2 (obj, 'A');
With bind method can create a new function that does not belong to class and can set 'this' parameter with a fixed object;
this.func1 = this.func1.bind(aObject)
In arrow functions, this binds to the object that defined the arrow function and that the object passed to the function asthis parameter.