class Tuxedo {
constructor( args ) {
this.propName = someValue
}
instanceFunction() { ... }
static staticFunction() { ... }
get propertyName() {
return theValue
}
set propertyName(theValue) { ... }
}
export default class MyModel { ... }
import any_name from './MyModel'
export class MyClass { ... }
export function floof() { ... }
import { MyClass, floof } from './Stuff'
import * as stuff from './Stuff'
var factionsList = []
for (var m in factions) {
factionsList.push( factions[m] )
}
WARNING: Don't use for arrays.
for (const item of iterable) { ... }
for (const codePoint of string) { ... }
for (let i = 0; i < someSize; ++i) { ... }
var rawTypes = require("Netrunner/types")
var types = rawTypes.data.reduce( (obj, type) => {
obj[type.code] = type
return obj
}, {})
filtered = items.filter( item => boolExpr(item) )
sorted = items.sort( (a,b) => a - b )
fetch( url ).then( (resp) => {
return response.json()
}).then( (data) => {
//handle data
}).catch( (err) => {
console.log( err.message )
})
Warning: Some JS functions work with broken UCS-2. Iterables however work with code points.
Should work as-is in strings (utf8 file encoding)
'\uABCD'
'\u{ABCDE}'
var mapped = someArray.map( x => expr(x) )
var total = someArray.reduce( (prev,next) => prev + next )
Also reduceRight
function mult( ...theValues ) {
return theValues.reduce( (p,c) => {
return p * c
})
}
arr.push( valueAtEnd )
arr.splice( index, 0, insert@Index )
var arrOfRemoved = arr.splice( index, 1 ) //remove 1 item at index
var firstItem = arr.shift()
var lastItem = arr.pop()
var subArr = arr.slice( startIndex [, endIndex] )
var copy = arr.slice()
//-1 if not found, also `lastIndexOf`
var index = arr.findIndex( (element [, index]) => boolExpr() )
var value = arr.find( (elemen [, index]) => boolExpr() )
var yesNo = arr.includes( value [, startIndex])
var list = arrItems.join( "-" )
num5_14 = Array.from(new Array(10), (x,i) => i + 5)
num0_9 = [...Array(10).keys()]
charsA_D = Array.from(new Array(5), (x,i) => String.fromCharCode('A'.charCodeAt(0) + i))