-
Shortening
constto something likeref,val,cstbecause- it's the most frequently used keyword
- conflicts with
console.logauto-completion
-
nullshould beObject.freeze(Object.create(null))or a specialSymbol.nullable -
([] =~= []) // trueshallow compare -
({ a: {} } =*= { a: {} }) // truedeep compare
// (,i)=>i // would be like (_, i)=>i, (IGNOREME, i)=>i, or (...[,i])=>i
// someFunction(a,,b) // someFunction(a, undefined, b), someFunction(...[a,,b])
// actually, you just make a function for those cases, e.g.:
const range = (length, cb=x=>x) => Array.from({length}, (_,i)=>cb(i))- Making
someArray[-i]besomeArray[someArray.length-i]for any strictly positive integeri.
However it could break old applications. I've usedM[-1],M[-2]for matrices for examples, for more easily using adjacent rows/cells (without if conditions), but it's hacky and avoidable
class A extends Array{ get [-1]() {return this[this.length-1] } } // or
Object.defineProperty(Array.prototype, -1, { get() {return this[this.length - 1] } }); // sigh- Extend
.sliceto be variadic, and concats all pairs of arguments, it makes things like removing one item easy:a.slice(0, i, i+1)(without mutation)
const {slice} = Array.prototype;
Array.prototype.slice = function(...a){ const args=Array.from({length:Math.ceil(a.length/2)}, (_,i)=>[a[2*i],a[2*i+1]]); return args.reduce((b,x)=>b.concat(slice.call(this, ...x)), [])};- Extend
.jointo be variadic:
Array.prototype.join = function(...arr){ return (this[0]||'')+this.slice(1).reduce((a,s,i)=>a+(arr[i]||',')+s, '') }; [1,2,3].join('__', '@')