Skip to content

Instantly share code, notes, and snippets.

View rahgurung's full-sized avatar
💻
Working

Rahul Gurung rahgurung

💻
Working
View GitHub Profile
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!
function doSomething() {
// "use strict"; // uncomment to run in strict mode
console.log( this.x );
}
var obj = {
x: "Hello World!"
}
var x = "global"
// This example is supposed to run on Console of any modern browser
var x = "Hello World!";
console.log(window.x); // "Hello World!"
function first() {
// call-stack: `first`
// call-site: global-scope
second(); //
}
function second() {
// call-stack: `first->second`
// call-site is in `first`
third();
function doSomething() {
return this.a;
}
var x = doSomething.bind({a: 'Hello World!'});
console.log(x()); // Hello World!
@rahgurung
rahgurung / this.js
Last active December 6, 2021 19:01
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
<button onclick="console.log(this.tagName.toLowerCase())">
Click to see the name of tag
</button>
import * as React from 'react';
import { Text } from 'react-native';
// Imports related to navigation
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
// Initialize the Stack navigator
const Stack = createNativeStackNavigator();
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>;
}
import * as React from 'react';
import {Text, Button} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
// Our Screens
function Screen1({navigation}) {
return (
<>
<Text>Screen 1</Text>