Skip to content

Commit 545d46b

Browse files
committed
Test variable type by present of methods; avoid typeof
Make the code shorter by testing whether elements is a string or an arary by presence of a join method rather than using typeof.
1 parent 7778b26 commit 545d46b

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/html5shiv-printshiv.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @preserve HTML5 Shiv 3.7.4-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
2+
* @preserve HTML5 Shiv 3.7.4-pre | @afarkas @jdalton @jon_neal @rem @mina86 | MIT/GPL2 Licensed
33
*/
44
;(function(window, document) {
55
/*jshint evil:true */
@@ -78,7 +78,7 @@
7878
*/
7979
function getElements() {
8080
var elements = html5.elements;
81-
return typeof elements == 'string' ? elements.split(' ') : elements;
81+
return elements.join ? elements : elements.split(' ');
8282
}
8383

8484
/**
@@ -89,17 +89,17 @@
8989
*/
9090
function addElements(newElements, ownerDocument) {
9191
var elements = html5.elements;
92-
if(typeof elements != 'string'){
92+
if (elements.join) {
9393
elements = elements.join(' ');
9494
}
95-
if(typeof newElements != 'string'){
95+
if (newElements.join) {
9696
newElements = newElements.join(' ');
9797
}
98-
html5.elements = elements +' '+ newElements;
98+
html5.elements = elements + ' ' + newElements;
9999
shivDocument(ownerDocument);
100100
}
101101

102-
/**
102+
/**
103103
* Returns the data associated to the given document
104104
* @private
105105
* @param {Document} ownerDocument The document.

src/html5shiv.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @preserve HTML5 Shiv 3.7.4-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
2+
* @preserve HTML5 Shiv 3.7.4-pre | @afarkas @jdalton @jon_neal @rem @mina86 | MIT/GPL2 Licensed
33
*/
44
;(function(window, document) {
55
/*jshint evil:true */
@@ -78,7 +78,7 @@
7878
*/
7979
function getElements() {
8080
var elements = html5.elements;
81-
return typeof elements == 'string' ? elements.split(' ') : elements;
81+
return elements.join ? elements : elements.split(' ');
8282
}
8383

8484
/**
@@ -89,17 +89,17 @@
8989
*/
9090
function addElements(newElements, ownerDocument) {
9191
var elements = html5.elements;
92-
if(typeof elements != 'string'){
92+
if (elements.join) {
9393
elements = elements.join(' ');
9494
}
95-
if(typeof newElements != 'string'){
95+
if (newElements.join) {
9696
newElements = newElements.join(' ');
9797
}
98-
html5.elements = elements +' '+ newElements;
98+
html5.elements = elements + ' ' + newElements;
9999
shivDocument(ownerDocument);
100100
}
101101

102-
/**
102+
/**
103103
* Returns the data associated to the given document
104104
* @private
105105
* @param {Document} ownerDocument The document.

0 commit comments

Comments
 (0)