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 doSomething(a) { | |
this.x = "Hello"; | |
this.y = "World!"; | |
} | |
var bar = new doSomething(); | |
// `this` has been bound to bar here | |
console.log(bar.x); // Hello | |
console.log(bar.y); // World! |
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 doSomething() { | |
// "use strict"; // uncomment to run in strict mode | |
console.log( this.x ); | |
} | |
var obj = { | |
x: "Hello World!" | |
} | |
var x = "global" |
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
// This example is supposed to run on Console of any modern browser | |
var x = "Hello World!"; | |
console.log(window.x); // "Hello World!" |
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 first() { | |
// call-stack: `first` | |
// call-site: global-scope | |
second(); // | |
} | |
function second() { | |
// call-stack: `first->second` | |
// call-site is in `first` | |
third(); |
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 doSomething() { | |
return this.a; | |
} | |
var x = doSomething.bind({a: 'Hello World!'}); | |
console.log(x()); // Hello World! |
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
var doSomething = (() => this.a); | |
var a = "From Global"; | |
var Context = {a: 'Hello World!'}; | |
// Use bind to set the `this` context | |
var x = doSomething.bind(Context); | |
console.log(x()); // From Global | |
// Use call to set the `this` context |
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
<button onclick="console.log(this.tagName.toLowerCase())"> | |
Click to see the name of tag | |
</button> |
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
import * as React from 'react'; | |
import {Text} from 'react-native'; | |
import {NavigationContainer} from '@react-navigation/native'; | |
import {createNativeStackNavigator} from '@react-navigation/native-stack'; | |
// Our Screens | |
function Screen1() { | |
return <Text>Screen 1</Text>; | |
} |