var calculator = { read : function(){ var sumOne = prompt('enter one number', ''); console.log(sumOne); }; calculator.read(); console.log(calculator.read.sumOne); How to output sumOne to the console not in the object.
var calculator = { read : function(){ var sumOne = prompt('enter one number', ''); console.log(sumOne); }; calculator.read(); console.log(calculator.read.sumOne); How to output sumOne to the console not in the object.
sumOne is a local variable in the function that cannot be accessed from outside. But it can be returned from the function:
var calculator = { read: function() { var sumOne = prompt('enter one number', ''); return sumOne; } }; var number = calculator.read(); console.log(number); sumOne , but an object with the option sumOne . Those. return {sumOne: sumOne} . As a result, calculator.read().sumOne will be called. This is in addition to your answer - Vasily BarbashevSource: https://ru.stackoverflow.com/questions/591070/
All Articles