loading
open in
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Language  {
   constructor(name,version) {
     this._name = name;
     this._version = version;
   }
   get name() {
     return this._name;
   }
   set name(value) {
     this._name = value;
   }
   get version() {
     return this._version;
   }
   set version(value) {
     this._version = value;
   }
   hello() {
     return "Hello from " + this.name;
   }
}

// Create object instances from class
let javascript = new Language("JavaScript","5");

// Verify property value access through getters 
console.log(javascript.name);
console.log(javascript.version);
console.log(javascript.hello());

// Reassign property values through setters
javascript.name = "ECMAScript";
javascript.version = "ES2015";

// Verify property value updates through getters
console.log(javascript.name);
console.log(javascript.version);
console.log(javascript.hello());
Native Browser JavaScript