-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.js
74 lines (50 loc) · 1.67 KB
/
application.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
65
66
67
68
69
70
71
72
73
74
var createGreeting = function(message, name) {
return message + name ;
}
// In the arrow function expression you don't use the return keyword
// In the arrow function expression you do not have to use the braces.
//multi-variable
var arrowGreeting = (message,name ) => message + name;
// single variable
var arrowSingleVarGreeting = message => "Single Variable"
/**
* var oldES5Greeting = function(message) {
* return message;
* }
*
*/
var squared = x => x * x ;
// console.log(createGreeting("Hello ", "Chris"));
console.log(arrowGreeting("Hello ", "Chris"));
console.log(arrowSingleVarGreeting("Single Variable"));
console.log(squared(5));
var deliveryBoy ={
name: "Old Boy",
handleMessage: function (message,handler){
handler(message);
},
receive: function () {
this.handleMessage("Hello, ", message => displayInPreview(message + this.name));
}
}
deliveryBoy.receive();
var arrowFunctionDeliveryBoy = {
name: "Chris",
handleMessage: function (message,handler){
handler(message);
},
receive: function () {
var that = this; // get proper name
this.handleMessage("Hello, ", (message) => {
that.name ;
console.log(message + that.name);
})
}
}
arrowFunctionDeliveryBoy.receive();
function displayInPreview(string) {
var newDiv = document.createElement("div");
var newContent = document.createTextNode(string);
newDiv.appendChild(newContent);
document.body.appendChild(newDiv)
}