Premise:
So whether you construct from a function
or es6 class
or base class
you are supposed to initialize like (for now let's ignore short-hand constructors):
const Fruit = function(name) {this.name = name}
class Ball {
constructor(color) {this.color = color}
}
const apple = new Fruit('apple')
const red_ball = new Ball('red')
const ob = new Object()
const arr = new Array()
Confusion:
But here's the thing, if I killed the new
keyword above in all statements:
Class
Uncaught TypeError: Class constructor A cannot be invoked without 'new'
Function
(Es5 class)Undefined
Array / Base Classes
- It initialized correctly! but Why?[]
or{}
Thoughts:
It could be a really stupid question, but I cannot find any references as to why that's the case, but this behavior seems to unanimously apply in Chrome, Firefox, Edge, and Node.js