Skip to content

Commit 705e8ba

Browse files
committed
Remove unnecessary anonymous scope
Creating an annonymous scope requires creation of a function which can only be done with a rather long ‘function’ keyword. This isn’t helping with minification so it’s better avoidid in possible. Wrapping try-catch blocks in a function helps with engine’s optimisation but HTML5 Shiv is hardly a piece of code which needs to be super-fast. Furthermore, browsers which don’t support HTML5 are likely to not benefit from the optimisation either. Get rid of the anonymous function.
1 parent 8e1f614 commit 705e8ba

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

src/html5shiv-printshiv.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,26 @@
3030
/** Detect whether the browser supports unknown elements */
3131
var supportsUnknownElements;
3232

33-
(function() {
34-
try {
35-
var a = document.createElement('a');
36-
a.innerHTML = '<xyz></xyz>';
37-
//if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
38-
supportsHtml5Styles = ('hidden' in a);
39-
40-
supportsUnknownElements = a.childNodes.length == 1 || (function() {
41-
// assign a false positive if unable to shiv
42-
(document.createElement)('a');
43-
var frag = document.createDocumentFragment();
44-
return !(frag.cloneNode &&
45-
frag.createDocumentFragment &&
46-
frag.createElement);
47-
}());
48-
} catch(e) {
49-
// assign a false positive if detection fails => unable to shiv
50-
supportsHtml5Styles = true;
51-
supportsUnknownElements = true;
52-
}
53-
54-
}());
33+
try {
34+
var a = document.createElement('a');
35+
a.innerHTML = '<xyz></xyz>';
36+
//if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
37+
supportsHtml5Styles = ('hidden' in a);
38+
39+
supportsUnknownElements = a.childNodes.length == 1 || (function() {
40+
// assign a false positive if unable to shiv
41+
(document.createElement)('a');
42+
var frag = document.createDocumentFragment();
43+
return !(frag.cloneNode &&
44+
frag.createDocumentFragment &&
45+
frag.createElement);
46+
}());
47+
} catch(e) {
48+
// assign a false positive if detection fails => unable to shiv
49+
supportsHtml5Styles = true;
50+
supportsUnknownElements = true;
51+
}
52+
a = 0;
5553

5654
/*--------------------------------------------------------------------------*/
5755

src/html5shiv.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,26 @@
3030
/** Detect whether the browser supports unknown elements */
3131
var supportsUnknownElements;
3232

33-
(function() {
34-
try {
35-
var a = document.createElement('a');
36-
a.innerHTML = '<xyz></xyz>';
37-
//if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
38-
supportsHtml5Styles = ('hidden' in a);
39-
40-
supportsUnknownElements = a.childNodes.length == 1 || (function() {
41-
// assign a false positive if unable to shiv
42-
(document.createElement)('a');
43-
var frag = document.createDocumentFragment();
44-
return !(frag.cloneNode &&
45-
frag.createDocumentFragment &&
46-
frag.createElement);
47-
}());
48-
} catch(e) {
49-
// assign a false positive if detection fails => unable to shiv
50-
supportsHtml5Styles = true;
51-
supportsUnknownElements = true;
52-
}
53-
54-
}());
33+
try {
34+
var a = document.createElement('a');
35+
a.innerHTML = '<xyz></xyz>';
36+
//if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
37+
supportsHtml5Styles = ('hidden' in a);
38+
39+
supportsUnknownElements = a.childNodes.length == 1 || (function() {
40+
// assign a false positive if unable to shiv
41+
(document.createElement)('a');
42+
var frag = document.createDocumentFragment();
43+
return !(frag.cloneNode &&
44+
frag.createDocumentFragment &&
45+
frag.createElement);
46+
}());
47+
} catch(e) {
48+
// assign a false positive if detection fails => unable to shiv
49+
supportsHtml5Styles = true;
50+
supportsUnknownElements = true;
51+
}
52+
a = 0;
5553

5654
/*--------------------------------------------------------------------------*/
5755

0 commit comments

Comments
 (0)