Valid template expressions:
- expressions can reference any property on the passed in context, including nested properties and indexed access to array properties.
{{ name }}
{{ obj.name }}
// Listener | |
window.addEventListener('storage', handlerEvent) | |
// Whenever we set a localStorage, window object will listen and invoke this handlerEvent function. | |
// We do all validation and stuff to act accordingly. | |
// Handler | |
const handlerEvent = event => { | |
if (event.originalEvent.key != 'message') return |
// deferred | |
function poll(fn, timeout, interval) { | |
let endTime = Number(new Date()) + (timeout || 2000) | |
interval = interval || 100 | |
let checkCondition = (resolve, reject) => { | |
// If the condition is met, we're done! | |
let result = fn() | |
if (result) { |
// SHALLOW COPY | |
const obj1 = { | |
a: 1, | |
b: 2, | |
c: 'three', | |
d: new Date() | |
} | |
const obj2 = { |
const canvas = document.querySelector('canvas') | |
const debounce = (func) => { | |
let timer | |
return (event) => { | |
if (timer) { clearTimeout(timer) } | |
timer = setTimeout(func, 100, event) | |
} | |
} |
// Javascript Currying and Partial Application Examples | |
const multiplier = x => { | |
return (y, z) => { | |
return z * y * z | |
} | |
} | |
const mult = multiplier(10) // x | |
mult(20, 30) // y, z |
// https://alligator.io/js/cache-api/ | |
if ('caches' in window) { | |
const cacheName = 'sample-caches' | |
const url = '/resource' | |
caches.open(cacheName).then(cache => { | |
return console.log(cache) | |
}) |
// Instantiate the Channel | |
const channel = new MessageChannel() | |
// Sending Messages Through the Channel | |
const data = { | |
color: 'blue', | |
title: 'Lorem ipsum dolor', | |
number: '000998909874564781', | |
content: 'Lorem ipsum dolor sit amet. Consectetur adicisping alet.', | |
} |
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback | |
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB; | |
// Open (or create) the database | |
var open = indexedDB.open("MyDatabase", 1); | |
// Create the schema | |
open.onupgradeneeded = function() { | |
var db = open.result; | |
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"}); |