D3.js
Author

(Rocha, 2019, pp. 51-52)

Funciones

Functions are typically created in JavaScript using the function keyword, using one of the forms below:

function f() {
    console.log('function1', this);
}
const g = function(name) {
    console.log('function ' + name, this);
}
f(); // calls f
g('test'); // calls g() with a parameter

The this keyword refers to the object that owns the function. If this code runs in a browser, and this is a top-level function created in the <script> block, the owner is the global window object. Any properties accessed via this refer to that object.

A function can be placed in the scope of an object, behaving as a method. The this reference in the following code refers to the objobject and can access this.a and this.b:

const obj = {a: 5, b: 6}
    obj.method = function() {
        console.log('method', this)
    }
object. method()

Arrow functions were introduced in ES2015.