With 15+ years of dev experience, I'm an online educator, mentor, and consultant--teaching practical, advanced topics to developers like you on how to write: ā maintainable JS code ā scalable web apps ...yup that's about it! š¤
Nothing here yet.
Bonus tip: how to turn your POO (plain old object) into an iteratable array! const obj1 = {a: 1 , b: 2 }; obj1.__proto__[Symbol.iterator] = function * ( ) { for (const k in this ) yield [k, this [k]]; } for (const e of obj1) console.log(e.join( ":" )) // a:1 // b:2
For an IFace1 object, if you call Object.keys() on it, it will always return an array with "NotOptional" it it. Not so with IFace2 . Like you said, in practical terms that's mostly useful for memory allocation. But sometimes there can also be subtle implications as well; kinda like the difference between null and undefined.
One of my favourite util functions using Array.from: const listRange = ( begin, end, inc = 1 ) => Array .from({ length : Math .ceil((end - begin) / inc) }, ( _, i ) => begin + i * inc); // console.log(listRange(0, 4, 1)); // [0, 1, 2, 3] // console.log(listRange(0, 4)); // [0, 1, 2, 3] // console.log(listRange(1, 10, 2)); // [1, 3, 5, 7, 9]