Skip to content

Commit f7e3665

Browse files
committed
Init
First upload of all files. If no changes or new files are needed than this upload should be final.
1 parent 755b170 commit f7e3665

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

block.js

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
NOTE:
3+
the varibale "elMedia" serves here only for demonstartion purposes.
4+
Global vaiables should be avoided!
5+
*/
6+
7+
8+
9+
//A list with all checked media
10+
var elMedia = [];
11+
12+
13+
//Lists all checked electro Media
14+
function checkElectroMedia()
15+
{
16+
var media = document.getElementsByClassName('Emedia');
17+
18+
for(var i = 0; i < media.length; i++ )
19+
{
20+
if(media[i].checked)
21+
{
22+
23+
elMedia.push(media[i]);
24+
}
25+
26+
}
27+
}
28+
29+
30+
31+
//Version false: checkMedia, checkElectroMedia
32+
//Version true: checkMedia, checkMedia
33+
function Version(broken)
34+
{
35+
36+
var checkMedia = checkElectroMedia;
37+
var result = document.getElementById('result');
38+
39+
40+
result.innerHTML = " "; //Reset content
41+
elMedia.length = 0; //Reset array by putting its length to zero
42+
43+
44+
//Set to true to check block scoping
45+
if(true)
46+
{
47+
48+
var media = document.getElementsByClassName('Nmedia');
49+
var noelMedia = [];
50+
51+
/*
52+
ATTENTION:
53+
Overwrites the variable "media" as a new function
54+
and stays overwritten after leaving the if-block!
55+
56+
*/
57+
checkMedia = function()
58+
{
59+
60+
61+
for(var i = 0; i < media.length; i++ )
62+
{
63+
if(media[i].checked)
64+
{
65+
66+
noelMedia.push(media[i]);
67+
}
68+
69+
}
70+
71+
}
72+
73+
74+
checkMedia();
75+
76+
77+
//Showing the result in browser
78+
for(var j = 0; j < noelMedia.length; j++)
79+
{
80+
result.innerHTML += " " + noelMedia[j].value;
81+
}
82+
}
83+
84+
85+
86+
if(broken)
87+
{
88+
/*
89+
ATTENTION:
90+
Function does not work as "checkElectroMedia"
91+
*/
92+
checkMedia();
93+
}
94+
else
95+
{
96+
/*
97+
ATTENTION:
98+
Works fine as expected
99+
*/
100+
checkElectroMedia();
101+
}
102+
103+
104+
//Showing the result in browser
105+
for(var j = 0; j < elMedia.length; j++)
106+
{
107+
result.innerHTML += " " + elMedia[j].value;
108+
}
109+
110+
}

index.html

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE HTML>
2+
3+
<html>
4+
5+
<head>
6+
7+
<title>Unportable scoping</title>
8+
<meta charset = "UTF-8">
9+
10+
</head>
11+
12+
13+
<body>
14+
15+
<h2>Checklist</h2>
16+
17+
<h3>Electronic Media</h3>
18+
<input type = "checkbox" class = "Emedia" value = "Movie">Movie
19+
<br>
20+
<input type = "checkbox" class = "Emedia" value = "Music">Music
21+
<br>
22+
23+
24+
<h3>Nonelectronic Media</h3>
25+
<input type = "checkbox" class = "Nmedia" value = "Book">Book
26+
<br>
27+
<input type = "checkbox" class = "Nmedia" value = "Storyteller">Storyteller
28+
<br>
29+
30+
31+
<br>
32+
<button type = "button" onclick = "Version(false)" >WORKING</button>
33+
<button type = "button" onclick = "Version(true)" >BROKEN</button>
34+
35+
36+
<ul>
37+
<li id = "result" ></li>
38+
</ul>
39+
40+
<br>
41+
<br>
42+
For more explanation please visit -
43+
<a href = "https://github.com/Incrementis/block-local-function-declarations-/wiki">
44+
Unportable scoping Wiki</a>
45+
46+
47+
</body>
48+
49+
50+
<script language = "javascript" type = "text/javascript" src = "block.js"></script>
51+
52+
</html>

wiki_images/Figure1.JPG

18 KB
Loading

wiki_images/Figure2.JPG

33.7 KB
Loading

wiki_images/Figure3.JPG

34.3 KB
Loading

0 commit comments

Comments
 (0)