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
// 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 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
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() { | |
console.log( this.x ); | |
} | |
// This is the context object | |
var obj = { | |
x: "Hello World!", | |
y: doSomething | |
} |
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 x = "Hello World!"; | |
// Here the call-site of the function is global scope | |
doSomething(); // "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 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); |
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 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); |
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 increase() { | |
// increment each time | |
this.x++; | |
} | |
// Create a property to the function object | |
increase.x = 0; | |
// Call function few times | |
increase(); |
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
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 | |
} |