What is my error when working with objects?

When you call the object, the values are not displayed. Maybe a syntax error?

But if the object is to leave 1 key, the value is called. Can't understand:(

Code: https://jsfiddle.net/75xqd1xg/
June 5th 19 at 21:43
1 answer
June 5th 19 at 21:45
Solution
The problem is that:

1. You keys asked the results of functions, not functions themselves;
2. You returned the key values, while it was necessary to call the functions.

Working option: https://jsfiddle.net/46par1r8/
Thanks for explaining, now I understand. Thank you for your help:) - Cielo_Ritch commented on June 5th 19 at 21:48
I just do not understand this syntax _ =>. What does it mean? - Cielo_Ritch commented on June 5th 19 at 21:51
Is Arrow functions - Shanel_Barton5 commented on June 5th 19 at 21:54
I understand, but why it applies here and not just obj.key? This moment can not understand. I just started learning js and this kind of work with objects not yet studied. - Cielo_Ritch commented on June 5th 19 at 21:57
,

When you write
let obj = {
 val1: document.querySelector('input[name=inputData]').setAttribute('class', 'bgred')
};


You create an object obj, val1 field which then equals the RESULT of the execution of the document.querySelector('input[name=inputData]').setAttribute('class', 'bgred'), while every time obj.val1 you just get already has once result.

In this case
let obj = {
 val1: function () { document.querySelector('input[name=inputData]').setAttribute('class', 'bgred') }
};

You create an object obj, val1 field which contains a pointer to a function function () { document.querySelector('input[name=inputData]').setAttribute('class', 'bgred') }. Accordingly, you can call this function when you need this way: obj.val1();

And _ => same as () => almost the same as function () {}, it's from ecmascript 6, more here: https://habr.com/post/252323/ - harmon_Carter86 commented on June 5th 19 at 22:00
thanks , quite understandable))) - Cielo_Ritch commented on June 5th 19 at 22:03

Find more questions by tags JavaScript