In completing this task, two key elements are being addressed:
var domStrings = {
inputType: '.add__type',
inputDescription: '.add__description',
inputValue: '.add__value',
addButton: '.add__btn'
}
The variable domstrings
is initialized as var domStrings
and then assigned with =
.
This action establishes a memory location where an object has just been created.
An object in JavaScript functions like a dictionary, housing key:value pairs where the key can be a string or number.
Object declaration follows this syntax: { 'key': 'value' .... }.
The value within an object can encompass various JS types such as strings, numbers, void, functions, or other objects.
A separate variable can point to the same object in memory:
var a = domStrings;
a.inputType /// '.add__type'
If a new assignment is made to domStrings
:
domStrings = "nope"
domStrings
now directs to a distinct memory location:
domStrings.inputType // undefined - "nope" lacks a property inputType
a
still points back to the original object:
a.inputType // '.add__type'
Therefore, by making that statement, a variable (domStrings) is declared, an object is generated in memory, and then the object is assigned to the variable, creating a reference to it.
Does this clarification address your initial query?
The second aspect revolves around what's referred to as a closure. It represents an IIFE - "Immediately Invoked Function Execution" - functioning as a secluded environment akin to a black hole singularity. The internal operations within this function closure have visibility internally; however, when viewed from outside, the external value of UIController
appears as:
{
getinput:() => {...},
getDomStrings: () => domstrings
}
The getDomStrings
function embedded within UIController accesses the domstrings
variable, offering an outward pointer while still confined within the closure itself.
Similarly, the getInput
function taps into this information to determine the object returned during its execution.
Certain code/data dissemination between functions inside a closure is feasible, with embargoed access from outside unless a referential passageway like getDomStrings
is employed.
...