-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.js
104 lines (70 loc) · 2.5 KB
/
receiver.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
NOTE:
The output of "console.log" should be watched in the debugger of a browser.
It should contain more details about the context.
The function "invocingFunction" is invoced within the file "index.html" by
"onclick = 'new invocingFunction('Oreo','Stiks', 42)'".
Also global vaiables serve here only for demonstartion purposes.
They should be avoided!
It is recommended to understand and play around with the code.
*/
var globe = document.getElementById('global');
function globalVariable()
{
var results = document.getElementById('results_one');
/*
ATTENTION - Context of variable "globe"
"this.globe" exists in the context of window, but as an "HTMLInputElement" object,
it offers an context in itself.
*/
results.innerHTML = "<li>Tag:<strong> " + this.globe + "</strong></li>";
results.innerHTML += "<li>Context is window: " + "<strong>" + (this.globe === window.globe) + "</strong></li>";
results.innerHTML += "<li>Input:<strong> " + this.globe.value + "</strong></li>";
console.log(this.globe);
}
function globalFunction()
{
var results = document.getElementById('results_one');
/*
ATTENTION - Context of function "globalFunction"
*/
results.innerHTML = "<li>Context: <strong>" + this + "</strong></li>";
console.log(this);
}
var newContext =
{
info: function(myForename, myName, myAge)
{
//Getting object attributes within its context
this.forename = myForename;
this.name = myName;
this.age = myAge;
var results = document.getElementById('results_two');
/*
ATTENTION - Context of method "info"
*/
results.innerHTML = "<li>Context:<strong> " + this + "</strong></li>";
results.innerHTML += "<li>Forename:<strong> " + this.forename + "</strong></li>";
results.innerHTML += "<li>Name:<strong> " + this.name + "</strong></li>";
results.innerHTML += "<li>Age:<strong> " + this.age + "</strong></li>";
console.log(this);
},
forename: "",
name: "",
age: 0
};
function invocingFunction(myForename, myName, myAge)
{
this.forename = myForename;
this.name = myName;
this.age = myAge;
var results = document.getElementById('results_two');
/*
ATTENTION - Context of function "invocingFunction"
*/
results.innerHTML = "<li>Context:<strong> " + this + "</strong></li>";
results.innerHTML += "<li>Forename:<strong> " + this.forename + "</strong></li>";
results.innerHTML += "<li>Name:<strong> " + this.name + "</strong></li>";
results.innerHTML += "<li>Age:<strong> " + this.age + "</strong></li>";
console.log(this);
}