This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionTypes { | |
static REBALANCE = Symbol("REBALANCE"); | |
static MESSAGE = Symbol("MESSAGE"); | |
static FETCH = Symbol("FETCH"); | |
static { | |
const enumMap = new Map(); | |
for (const [key, value] of Object.entries(this)) { | |
enumMap.set(key, value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import atexit | |
import optparse | |
import os | |
from select import select | |
import shutil | |
from socket import (error, | |
socket, | |
AF_INET, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------- initial code ---------------------------- | |
// index.js | |
import { someObject } from './ModuleA'; | |
console.log(someObject.property); | |
// ModuleA.js | |
export const someObject = { | |
property: 100 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function constructorFn() { | |
this.x = 100; | |
} | |
constructorFn.prototype.nonStaticFn = function() { | |
return this.x; | |
} | |
constructorFn.staticFn = function() { | |
// this.x; undefined | |
return 200; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// No need to use "let" here since we never reassign the arr | |
const arr = []; | |
arr.push({ property: 1 }); | |
// ----------------------------------------------- | |
// If we want to clear the array by reassigning: | |
// | |
// because we're reassigning a new arr2 to the variable "arr", | |
// arr1 isn't assigned anymore and therefore gets flagged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Of course this is badly written on purpose | |
// using a constructor fn but it shows that | |
// .hasOwnProperty is obsolete when using | |
// e.g. Object.keys() | |
function modes() { | |
this.type1 = 1; | |
this.type2 = 2; | |
this.type3 = 4; | |
} | |
modes.prototype.type4 = 2; // This is our problem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example: Not so concise, not reusable | |
const component = { signals: [-33, -70, -80] }; | |
function highlightComponent() { | |
// isHighlighted isn't reusable but also no allocation for an extra function happens (see below) | |
let isHighligted = false; | |
for (let signal of component.signals) { | |
if (signal > -34) { | |
isHighligted = true; | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _extends(subClass, superClass) { | |
if (typeof superClass !== "function" && superClass !== null) { | |
throw new TypeError( | |
"Super expression must either be null or a function, not " + | |
typeof superClass | |
); | |
} | |
// Set both __proto__ and prototype | |
// ---------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The class | |
class classFn { | |
constructor(x,y) { | |
this.x = x; | |
this.y = y; | |
} | |
multiply() { | |
return this.x * this.y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function constructorFn() { | |
this.someProperty = "oops!" | |
} | |
// We've forgotten the "new" | |
const instance = constructorFn(); | |
instance; //undefined | |
window.someProperty; // oops! |
NewerOlder