V
V
Viktor Komarov2018-03-06 19:49:30
JavaScript
Viktor Komarov, 2018-03-06 19:49:30

Store a property in an object whose value depends on another property?

Hello! I'm just getting started with js. I have a task that has the following structure
function papa(e){
return{value:e
sum:function(b){
this.e+=b
return this}
}
}
I need to create another property whose value will be e. But however, when the sum method is called, the value of both properties must change. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bhudh, 2018-03-06
@Victor_Komarov

Make the new property a getter function that will return e.
And don't forget to separate object properties with commas.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question