Skip to content

Instantly share code, notes, and snippets.

@julienetie
julienetie / ho-js.4.js
Last active July 4, 2020 12:41
ho-js.4.js
/*
If you don't want something mutable to remain mutable, create a new context.
*/
const createBasket = (externalMutable) => {
const privateConstant = 123;
let privateMutable = 'abc';
return {
get getValues(){ // New context
return {privateConstant, privateMutable, externalMutable};
},
@julienetie
julienetie / ho-js-3.1.js
Last active July 4, 2020 15:43
ho-js-3.1.js
/* Higher-Order JavaScript */
const point = (x, y) => {
point.distance = (a, b) => {
const dx = a.x - b.x;
const dy = a.y - b.y;
return Math.hypot(dx, dy);
};
Object.freeze(point);
return {x, y};
@julienetie
julienetie / ho-js-3.2.js
Last active July 4, 2020 14:55
ho-js-3.2.js
/* Object Oriented JavaScript */
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
static distance(a, b) {
const dx = a.x - b.x;
const dy = a.y - b.y;
@julienetie
julienetie / ho-js-1.2.js
Last active July 4, 2020 11:19
ho-js-1.2.js
/* Higher-Order JavaScript */
const rectangle = (height, width) => {
return () => {
// "height" and "width" are available privately
}
}
@julienetie
julienetie / ho-js-2.2.js
Last active July 4, 2020 15:42
ho-js-2.2.js
/* Higher-Order JavaScript */
const rectangle = (height, width) => {
const calcArea = () => height * width;
return {
get area(){
return calcArea();
},
calcArea
}
};
@julienetie
julienetie / ho-js-2.js
Last active July 4, 2020 15:42
ho-js-2.js
/* Object Oriented JavaScript */
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
// Getter
get area() {
return this.calcArea();
}
@julienetie
julienetie / ho-js-1.js
Last active July 4, 2020 11:21
ho-js-1.js
/* Object Oriented JavaScript */
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
@julienetie
julienetie / get-property.js
Last active November 13, 2019 11:40
getProperty ES6
const getProperty = (object) => {
return ([path]) => {
return path.split('.').reduce((acc, property) =>
acc[property] || null
,object);
};
};
// getProperty({a:{b:{c:'Hello World!'}}}) `a.b.c`
// "Hello World!"
@julienetie
julienetie / wavefront-prototype-x.js
Last active June 5, 2019 05:25
Wavefront View-Layer Engine - Prototype X
import { create, make } from 'wavefront'
// To create a component we first need to create a component-maker:
// Create keypad component-maker.
create('keypad', ({ title, keypadClass, option, noticeText }) => `
<div class="${keypadClass}">
<h1>${title}</h1>
<div $keys>
<div>On<div>
<div>Off<div>
@julienetie
julienetie / lit-html-correction.md
Created May 26, 2019 09:05
lit-html-correction.md

Highlight Template Literals in VSCode

By jesperorb

  1. Install extension lit-html
  2. Open the file:
~/.vscode/extensions/bierner.lit-html-1.3.0/syntaxes/lit-html.json
  1. Replace line: