Last active
August 31, 2019 10:09
-
-
Save reime005/16d68d0b03acbe78976a4fa4dc5f03f4 to your computer and use it in GitHub Desktop.
Very simply call and apply example JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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