forked from annette-arrigucci/es6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexical_this_example.html
More file actions
37 lines (35 loc) · 1.12 KB
/
lexical_this_example.html
File metadata and controls
37 lines (35 loc) · 1.12 KB
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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
document.writeln("ES5 way - passing in a thisArg for each iteration<br>");
var maria = {
_name: "Maria",
_friends: ["Nancy", "Annette", "John"],
printFriends: function() {
this._friends.forEach(function (element) {
document.writeln(this._name + " knows " + element + "<br>")
}, this);
}
}
var maria1 = Object.create(maria);
maria1.printFriends();
/*document.writeln("ES6 way - lexical this means no thisArg<br>");
var bob = {
_name: "Bob",
_friends: ["Nancy", "Annette", "John"],
printFriends: function() {
this._friends.forEach(f =>
document.writeln(this._name + " knows " + f + "<br>"));
}
}
var bob1 = Object.create(bob);
bob1.printFriends();
*/
</script>
</body>
</html>