LoginSignup
0
0

More than 3 years have passed since last update.

VanillaJSでgetter/setter

Last updated at Posted at 2020-10-07

こうする

function Clazz() {
    let hoge = "hogehoge";

    this.setHoge = function(param) {
        hoge = param;
    };
    this.getHoge = function() {
        return hoge;
    };
}

const a = new Clazz();
const b = new Clazz();

a.setHoge("ほげほげ")
console.log(a.getHoge()); // ほげほげ
console.log(b.getHoge()); // hogehoge
console.log(a.hoge); // undefined
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0