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
class Language  {
   constructor(name,version) {
     this.name = name;
     this.version = version;
   }
   hello() {
     return "Hello from " + this.name;
   }
}

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


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

// Properties can be added to an object instance just like in ES5 
// You can add a property to an instance
python.typed = 'Dynamically';
console.log(python.typed);
// But the javscript instance won't have a 'typed' property
console.log(javascript.typed); // undefined

// The 'prototype' is also accesible like in ES5 data types
Language.prototype.typed = "Dynamically";
// Now the javascript instance has a 'typed' property, because it was added to its prototype
console.log(javascript.typed);
Native Browser JavaScript