2

function normalize() {
console.log(this.coords.map(n => n / this.length));
}

normalize.call({coords: [0, 2, 3], length: 5});

Why? Why, javascript? Why do you invert the function and the 'this' keyword? It just confuses me and (at this time) I cannot think of a place where this would be really necessary.

Comments
  • 1
    I feel like I'm missing something here. What exactly are you trying to achieve with your example?
  • 2
    @mrmr I got this example of a book.

    Instead of simple parameters, the function is called by the ".call" and the parameters are used by "this." keyword inside the function.
  • 3
    @brunofontes Ah I see, a pretty bad example as it doesn't provide a valid use case.

    My confusion was around the fact that using call in that example was completely unnecessary 😂
Add Comment