I've just discovered that Magento 2's UI Component javascript constructor functions are built in such a way that they (seem to?) behave the same with, and without, the new
keyword;
UiElement = requirejs('uiElement');
//both instantiate a new object
object = new UiElement;
object = UiElement():
However, the UI Component registering code
#File: vendor/magento//magento2-base/lib/web/mage/layout.js
function initComponent(node, Constr) {
var component = new Constr(_.omit(node, 'children'));
registry.set(node.name, component);
}
appears to use the new
keyword when instantiating these objects.
Does anyone know if there's a downside to not using the new
keyword? The object system seems to have been designed such that you can use these constructor functions either way. However, without any core example or solid documentation on the topic, it leaves me wondering if this second, new
-less syntax is safe to use.
Hoping someone here knows the answer or can pass me on to someone who does.