forked from annette-arrigucci/es6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_example.html
43 lines (36 loc) · 1.08 KB
/
class_example.html
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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
//ES5
function Vehicle(type, color) {
this.type = type;
this.color = color;
}
var car = new Vehicle("Honda", "silver");
document.writeln("ES5 way<br>");
document.writeln("Car type is " + car.type +"<br>");
document.writeln("Car color is " + car.color);
/*
//ES6
class Vehicle {
constructor(type, color) {
this.type = type;
this.color = color;
}
getColor() {
return this.color;
}
}
let car = new Vehicle("Honda", "silver");
document.writeln("ES6 way using constructor and getColor()<br>");
document.writeln("Car type is " + car.type + "<br>");
document.writeln("Car color is " + car.getColor());
*/
</script>
</body>
</html>