In order to improve the code structure, I am looking to consolidate all properties into a JavaScript object instead of using multiple variables:
// Method 1
// This method gives an error as _inp cannot be accessed by input_value
// Uncaught TypeError: Cannot read property 'value' of undefined
var ref = {
_inp: input.target,
input_value: _inp.value,
....
};
// Method 2
// Using this method works without any errors
var ref = {
_inp: input.target,
input_value: input.target.value,
....
};
// Method 3
// This method also functions correctly.
var
_inp = input.target,
input_value = _inp.value,
My question is, why does Method 3 work while Method 1 does not?