In doing research for the new uElement
Internals series, I discovered that Magento’s UI Component object constructors (uiClass
, uiElement
, uiCollection
, etc) can create new objects without the use of the new
keyword.
//both return a new `UiElement` object
object = new UiElement;
object = UiElement();
This makes these constructor objects closer in behavior to Magento’s base helper classes like Object
and Array
. It is curious, however, that the view model registration 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);
}
choses to use the new
keyword when instantiating these objects. Perhaps it’s a sign that there’s multiple developers not talking to one another, or that there’s weird bugs/differences when using or not using the new
keyword. One is, once again, left in the dark without decent documentation on the subject.