Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Helpful example code to demonstrate the use of "this" in JavaScript for my article at
// Example 7. 'this' binding with bind()
var bulbasaur = {
pokédexNo: "001",
getPokédexNo: function() {
return this.pokédexNo;
var unboundGetPokédexNo = bulbasaur.getPokédexNo;
// The function gets invoked at the global scope
// Output: undefined
var boundGetPokédexNo = unboundGetPokédexNo.bind(bulbasaur);
// Output: "001"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment