Instantly share code, notes, and snippets.

View storage.js
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
// Define the storage type (local or session)
var Storage = function (type) {
// Define the storage type (local or session)
function setData(data) {
// Sets the data into storage
}
function clearData() {
// clears data from storage
}
View startsWith.js
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
View app-shell-sw.js
const staticCacheName = 'app-shell-static-v1';
const staticCacheFileNames = [
'public/offline.html',
'lib/app.js'
];
self.addEventListener('install', (event) => {
self.skipWaiting();
event.waitUntil(
View app-shell-app.js
(function () {
class App {
constructor() {
this.registerServiceWorker();
this._app = document.querySelector('.app');
this.fetchOfflineContent = this.fetchOfflineContent.bind(this);
this.fetchAppContent = this.fetchAppContent.bind(this);
self.addEventListener('online', this.fetchAppContent);
self.addEventListener('offline', this.fetchOfflineContent);
View app-shell-index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title> App Shell </title>
<style>
/* Critical Inline Styles */
View super.js
// ES6 style
class Gorilla extends Animal {
constructor(name, weight) {
super(name, weight);
}
showVigour() {
return `${super.eat()} ${this.poundChest()}`;
}
View extends.js
// ES6 style
class Gorilla extends Animal {
constructor(name, weight) {
super(name, weight);
}
//...
}
// Traditional style
function Gorilla(name, weight) {
View methods-comparison.js
// ES6 style
class Animal {
// ...
eat() {
return `${this.name} is eating!`;
}
sleep() {
return `${this.name} is going to sleep!`;
}
View class-declaration.js
// ES6 style
class Animal {
constructor(name, weight) {
this.name = name;
this.weight = weight;
}
//...
}
// Check Type of ES6 class
View ES5.js
function Animal(name, weight) {
this.name = name;
this.weight = weight;
}
Animal.prototype.eat = function() {
return `${this.name} is eating!`;
}
Animal.prototype.sleep = function() {