Skip to content

Instantly share code, notes, and snippets.

import inspect
def decorator_wrapper(parameter):
print parameter
def decorator(func):
def wrapper(message):
print "Wrapper start"
func(message)
print "Wrapper end"
var log = console.log
log("Inside global execution context")
function functionOne() {
log("Inside function one")
function setTimeoutFunction() {
log("Inside setTimeoutFunction: I will be executed after ECS become empty." +
"Though my waiting time is zero")
function printStatement() {
console.log("I will be printed after 0 milliseconds")
}
setTimeout(printStatement, 0)
console.log("Still, I will be executed first")
/* Output:
Still, I will be executed first
@happymishra
happymishra / executionContextStackExample.js
Last active June 16, 2019 06:42
Executuon context stack example
console.log("Inside global execution context")
// 'a' will be stored on ECS as it's a primitive value
var a = 10;
// Only reference of functionOne will be stored inside stack.
// funtionOne definition itseld will be stored on heap
function functionOne() {
console.log("Inside functionOne exectuon context")
function printStatement() {
console.log("I will be printed after 100 milliseconds")
}
setTimeout(printStatement, 100)
/* ******* Alternate syntax ******************/
/*
setTimeout can be written as this also
function multiplyByTwo (num) {
console.log(num + " multiplied by 2 is " + num*2)
}
// Syntax - setTimeout(callbackMethod, delay, param1, param2, ..)
setTimeout(multiplyByTwo, 100, 4)
// Output:
// 4 multiplied by 2 is 8
var timerId = setTimeout(function (){
console.log("This function will be removed before it's executed")
}, 100)
clearTimeout(timerId)
// No output will be displayed as the setTimeout callback function
// will be cancelled before it will be executed
var log = console.log
log("Inside global execution context")
function functionOne() {
log("Inside function one")
function setTimeoutFunction() {
log("Inside setTimeoutFunction: I will be executed atleast after 1 sec")
}
// Web Share APIs are provided by navigator.share method
if (navigator.share) {
console.log("Web Share APIs are supported")
} else {
console.log("Web Share APIs are not supported")
}
var shareButton = document.getElementById('share-button');
shareButton.addEventListener('click', function () {
// Check if navigator.share is supported by the browser
if (navigator.share) {
console.log("Congrats! Your browser supports Web Share API")
// navigator.share accepts objects which must have atleast title, text or
// url. Any text or title or text is possible