set value in javascript class -
I have written ia class for practice, can someone tell me why 2 prints instead of 1?
  function hnclass () {var h = 1; Function print () {console.info (h); // Printed 1} return {item: h, printout: print}} HC = new HClclass (); Hc.item = 2; Hc.printout (); Console.log (hc.item); // print 2    with  hc.item = 2;  I am changing the value of  item , after which, when I am calling a print function, it should print  2 . I was wondering if the setter function in such a class is possible without the set price? 
Anyone can tell me why it prints 2 instead of 1
Because setting the value of a variable or property never changes the value of any other variable or property, here is a simple example:
< Pre> var a = 1; Var B = A; A = 42; Assigning a new value to   to  a  does not change the value of  b , even if  b  is basically  A . 
 In your case, simply assigning a value to  hc.item  just  h .    I was wondering if a setter function is possible without such a set value in this class? 
              
  However, in this entire setup there really is nothing with OOP or classes. Perhaps you get a better understanding of the problem. 
 
Comments
Post a Comment