A free function is a [[programming language]] construct where a [[function]] is not bound to a particular object, such as a [[method]].
In the following example, f is a free function while obj.m is a method (obj.m can reference this[^fn:1] ):
function f() {
return "f";
}
const obj = {
m: function () {
return "m";
},
};
1 This example is somewhat misleading because in [[JavaScript]] a free function can become a method. Consider the following example:
function f() {
return this.name;
}
const obj = {
name: 'obj',
};
console.log('free func:\t', f());
obj.f = f;
console.log('method:\t', obj.f());
Further, in [[JavaScript]], this can be set in free functions:
function f() {
return `my name is ${this.name}`;
}
console.log(f.call({name: 'foo'}));