What's The Use Of get()


#1

What’s the use of objects and _ in JavaScript.


#2

it allows us to manipulate the behavior of properties:

obj = {
  _a: [],
  get a(){
    return this._a.join(" ")
  },
  set a(aIn){
    this._a.push(aIn)
  }
}

obj.a = 1
obj.a = 2
obj.a = 3
console.log(obj.a)

comment out/remove the getter (and or setter), to see th difference in behavior)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.