Skip to content

Instantly share code, notes, and snippets.

View anurag-majumdar's full-sized avatar
💭
Creativity is the art of application of learning.

Anurag Majumdar anurag-majumdar

💭
Creativity is the art of application of learning.
View GitHub Profile
function Animal(name, weight) {
this.name = name;
this.weight = weight;
}
Animal.prototype.eat = function() {
return `${this.name} is eating!`;
}
Animal.prototype.sleep = function() {
// ES6 style
class Animal {
constructor(name, weight) {
this.name = name;
this.weight = weight;
}
//...
}
// Check Type of ES6 class
// ES6 style
class Animal {
// ...
eat() {
return `${this.name} is eating!`;
}
sleep() {
return `${this.name} is going to sleep!`;
}
@anurag-majumdar
anurag-majumdar / extends.js
Created April 16, 2018 13:41
Comparison between ES6 and traditional approach to extending classes
// ES6 style
class Gorilla extends Animal {
constructor(name, weight) {
super(name, weight);
}
//...
}
// Traditional style
function Gorilla(name, weight) {
// ES6 style
class Gorilla extends Animal {
constructor(name, weight) {
super(name, weight);
}
showVigour() {
return `${super.eat()} ${this.poundChest()}`;
}
<!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 */
(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);
const staticCacheName = 'app-shell-static-v1';
const staticCacheFileNames = [
'public/offline.html',
'lib/app.js'
];
self.addEventListener('install', (event) => {
self.skipWaiting();
event.waitUntil(
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
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
}