What would be correct syntax for get/set methods

What would be correct syntax for get/set methods
0.0 0

#1

hi, can someone tell what would be the right way for get/set methods.

var book = function(number){
  let pages = number;
  //get method
  this.getPages(){
    return pages;
  };
 //set method
  this.setPages(num){
    pages = num;
  };
 };

or like using this handle again in set/get method

var book = function(number){
  let pages = number;
  //get method
  this.getPages(){
    return this.pages;
  };
 //set method
  this.setPages(num){
    this.pages = num;
  };
 };

#2

Hi! It would be easier knowing which task this is. I’m not that good at this but I think you should state that getPages is a function like so:
this.getPages = function(){
return pages;
};
and then do the same with setPages but passing the function your num argument:
this.setPages = function(num){
pages = num;
};
In setPages if you use this.pages then it doesn’t update the page number. Therefore, just ascribe a new value to pages (pages = num).
This way it works, at least for me.
Hope this helps.


#3

Getter

Setter