Conventional wisdom seems to be that using JavaScript as a classical language is bad: JavaScript's pillars are object-oriented (prototypal inheritance) and functional, not classical, say all the experts (e.g., @eric-elliott, Douglas Crockford, etc.).
Yet so many of our APIs use constructors and require the use of new
when instantiating an object. For example, if I want to fetch data with an AJAX call, I have to do something like let xhr = new XMLHttpRequest()
.
So, are we stuck with classical behaviour in JavaScript for now, until/unless APIs are updated? Or is there some way to excise all these new
declarations from our code, perhaps something along the lines of API factory functions or Object.create(XMLHttpRequest.prototype)
?