Last active
December 2, 2021 12:11
-
-
Save rahgurung/10929ce4c4b623e50394a2bc85a84ea5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 doSomething() { | |
// "use strict"; // uncomment to run in strict mode | |
console.log( this.x ); | |
} | |
var obj = { | |
x: "Hello World!" | |
} | |
var x = "global" | |
// passing the object to be used for `this` explicitly | |
doSomething.call(obj); // "Hello World! | |
doSomething.apply(obj); // "Hello World! | |
// passing the `null` and `undefined`, `this` will be bind to global scope | |
doSomething.call(null); // "Hello World! | |
doSomething.apply(null); // "Hello World! | |
doSomething.call(undefined); // "Hello World! | |
doSomething.apply(undefined); // "Hello World! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment