Guest User

Untitled

a guest
May 27th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. let parentObject = {
  2. initVal:10,
  3. addInitVal: () => {
  4. this.initVal += 1;
  5. },
  6. getVal: () => {
  7. return this.initVal;
  8. }
  9. }
  10. console.log(parentObject.initVal); //returns 10
  11. parentObject.addInitVal(); //add by 1
  12. console.log(parentObject.initVal); //still 10 ????
  13. console.log(parentObject.getVal()); //returns NaN ????
  14.  
  15. let parentObject = {
  16. initVal:10,
  17. addInitVal: function(){
  18. this.initVal += 1;
  19. },
  20. getVal: function(){
  21. return this.initVal;
  22. }
  23. }
  24. console.log(parentObject.initVal); //returns 10
  25. parentObject.addInitVal(); //add by 1
  26. console.log(parentObject.initVal); //returns 11
  27. console.log(parentObject.getVal()); //returns 11
Add Comment
Please, Sign In to add comment