Skip to content

Instantly share code, notes, and snippets.

@reime005
Last active August 31, 2019 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reime005/16d68d0b03acbe78976a4fa4dc5f03f4 to your computer and use it in GitHub Desktop.
Save reime005/16d68d0b03acbe78976a4fa4dc5f03f4 to your computer and use it in GitHub Desktop.
Very simply call and apply example JavaScript
function add(a, b) {
console.log(a + b);
console.log(this);
}
add(1, 2);
// ⇒ 3
// ⇒ Object [global] { global: [Circular], clearInterval ... }
add.apply({ example: "test" }, [1, 2]);
// ⇒ 3
// ⇒ { example: "test" }
add.call(null /* or undefined */, 1, 2);
// ⇒ 3
// ⇒ Object [global] { global: [Circular], clearInterval ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment