Skip to content

Instantly share code, notes, and snippets.

@AnimeshPandey
AnimeshPandey / 1_this_Example_2.js
Last active February 27, 2021 23:52
Helpful example code to demonstrate the use of "this" in JavaScript for my article at https://anmshpndy.medium.com/how-well-do-you-know-this-ce4355bc9b
// Example 2. Default Binding.
function getPokémon(){
console.log("Pokémon in Ultra Ball is : ", this.ultraBall);
}
var ultraBall = "Articuno";
getPokémon();
// Output
// Pokémon in Ultra Ball is : Articuno
@AnimeshPandey
AnimeshPandey / 1_this_Example_1.js
Last active February 27, 2021 23:52
Helpful example code to demonstrate the use of "this" in JavaScript for my article at https://anmshpndy.medium.com/how-well-do-you-know-this-ce4355bc9b
// Example 1. Call-sites and Call-stacks
function thunderbolt(){
debugger;
console.log("Using Thunderbolt!");
}
function attack(){
console.log("Attacking!");
thunderbolt(); // <- Call-site for thunderbolt()
}