Skip to content

Instantly share code, notes, and snippets.

View rahgurung's full-sized avatar
💻
Working

Rahul Gurung rahgurung

💻
Working
View GitHub Profile
function first() {
// call-stack: `first`
// call-site: global-scope
second(); //
}
function second() {
// call-stack: `first->second`
// call-site is in `first`
third();
// This example is supposed to run on Console of any modern browser
var x = "Hello World!";
console.log(window.x); // "Hello World!"
function doSomething() {
// "use strict"; // uncomment to run in strict mode
console.log( this.x );
}
var obj = {
x: "Hello World!"
}
var x = "global"
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() {
console.log( this.x );
}
// This is the context object
var obj = {
x: "Hello World!",
y: doSomething
}
function doSomething() {
// "use strict"; // uncomment to run in strict mode
console.log( this.x )
}
var x = "Hello World!";
// Here the call-site of the function is global scope
doSomething(); // "Hello World!"
function foo() {
var a = 2;
// This magically executes the bar() function
// we will explain this later in the article
this.bar();
}
function bar() {
console.log(this.a);
function increase() {
// increment each time
this.x++;
}
// Create a property to the function object
increase.x = 0;
// Call function few times with using itself as `this`
increase.call(increase);
function increase() {
// increment each time
this.x++;
}
// Create a property to the function object
increase.x = 0;
// Call function few times
increase();
@rahgurung
rahgurung / cpp.bash
Created November 9, 2019 13:40
script for c/c++ environment
make() {
if [ $1 = "run" ]; then
  g++ -Wall -o "$2" "$2".cpp
  ./"$2"
  printf "\n"
  else
  g++ -Wall -o "$1" "$1".cpp
  printf "Success! \n"
  fi
}