loading
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var literalLanguage = {
 "name":"Python",
 "version":"2.7",
 "hello":function() { return "Hello from " + this.name},
 get language() { 
   return this.name + " " + this.version;
 },
 set language(value) { 
  [this.name, this.version] = value.split(" ");
 },
};

// Verify property value access
console.log(literalLanguage.name);
console.log(literalLanguage.version);
console.log(literalLanguage.hello());
// Access language that uses get 
console.log(literalLanguage.language);

// Update language with setter 
literalLanguage.language = "JavaScript 5";

// Verify property values
// Access updated language that uses get
console.log(literalLanguage.language);
// language set updated inividual object properties  
console.log(literalLanguage.name);
console.log(literalLanguage.version);
console.log(literalLanguage.hello());

var Language = function(name,version) { 
 this.name = name;
 this.version = version;
 this.hello = function() { 
   return "Hello from " + this.name;
 }
};

var instanceLanguage = new Language("Python","2.7");

Object.defineProperties(Language.prototype, {
        language: {
             get: function()    { return this.name + " " + this.version; }
            ,set: function(value) { [this.name, this.version] = value.split(" ");   }
        }
});

// Verify property value access
console.log(instanceLanguage.name);
console.log(instanceLanguage.version);
console.log(instanceLanguage.hello());
// Access language that uses get 
console.log(instanceLanguage.language);

// Update language with setter 
instanceLanguage.language = "JavaScript 5";

// Verify property values
// Access updated language that uses get
console.log(instanceLanguage.language);
// language set updated inividual object properties  
console.log(instanceLanguage.name);
console.log(instanceLanguage.version);
console.log(instanceLanguage.hello());
Native Browser JavaScript