Stability: 2 - Stable
| // BUFFER | |
| // Load the whole content into a buffer/ into memory once before wrting it out to user | |
| const http = require("http"); | |
| const media = "./testvid.mp4"; | |
| const fs = require("fs"); | |
| http | |
| .createServer((req, res) => { |
| const watman = Array (16). join("wat" - 1) + " Batman!" | |
| console.log(watman); | |
| const watdahel = (![]+[])[+[]] + | |
| (![]+[])[+!+[]] + | |
| ([![]] +[][[]]) [+!+[] + [+[]]] + | |
| (![] + [])[!+[]+!+[]]; | |
| console.log(watdahel); |
A class's testability is improved through composition over inheritance. If a class is comprised of another class, it is simple to create a mock object to simulate the combined class for testing purposes.
Even while Composition and Inheritance both let you reuse code, Inheritance has the drawback of breaking encapsulation. If the function of the subclass depends on the superclass's action, it suddenly becomes vulnerable. Sub-class functionality may be broken without any alteration on the part of the super-class when its behaviour changes.
| /** | |
| * This was generated by GPTChat, but it is 100% correct. | |
| * Wrap a Promise that can be canceled. | |
| * @type {CancelablePromise} | |
| */ | |
| module.exports = class CancelablePromise { | |
| /** | |
| * Creates a new CancelablePromise object. | |
| * @class | |
| * @constructor |
Simple test to illustrate how
config.jsworks with regards to defaulting and overriding.
| /** | |
| Consider that this does not look at prototype, so will have issues with anything that is a class or has a prototype | |
| OR better | |
| https://lodash.com/docs/4.17.15#has | |
| **/ | |
| const hasAnyAttrs = (obj, attrs) => { | |
| if (obj && !!attrs) { | |
| return (attrs||[]).map(attr => obj[attr] !== undefined).filter(_ => _).length !== 0 |
WORK IN PROGRESS
Optional Chaining: The optional chaining?.operator accesses an object's property or calls a function. If the object accessed or function called isundefinedornull, it returnsundefinedinstead of throwing an error.
It should be noted, that this ES6 feature has been the topic of debate amongst established experts such as Kyle Simpson. His and other's opinions are justified. Kyle dislike is so strong he wrote an ESLINT Plugin. However, its my opinion this doesnt mean that the feature is without merits. JavaScript by its very nature is filled with issues, knowing what they are and avoiding or using them when appropiate is a pragmatic aproach.
Its a common misconception that Optional Chaing was intended for replacing short-circuting
| ## with this example, I can auto create the spec files based on functions | |
| for item in `find ./src/controllers/external -type f` | |
| do | |
| FILENAME=`basename -s .js $item` | |
| touch ./test/controllers/external/$FILENAME.spec.js | |
| done | |
| ## --------------------- | |
| ## basename ./src/controllers/external/storeApi.js |