Saturday, December 17, 2016

Rediscovering Javascript by Venkat Subramaniam

Venkat is brilliant https://youtu.be/r9XAp3CWRf4?t=30m14s

Using the Implicit Context Object


var greet = function(name) {
  console.log(this.toUpperCase() + ' ' + name);
}
// greet('Joe'); // blows up
greet.call('hello', 'Joe'); // 'hello' becomes the implicit 'this'
> HELLO Joe

Using Arguments Array and Apply

var greet = function(name1, name2) {
  console.log(this.toUpperCase() + ' ' + name1 + ' ' + name2);
}
greet.apply('hi', ['Jack', 'Jill']); 
> HI Jack Jill