It only takes 0.15ms for this line in my constructor function to execute.
[].push.apply(this, selector);
I'm not satisfied with the 0.15ms execution time. I believe there must be a quicker alternative available.
This particular line seems to be converting NodeList/HTMLCollection to an array. But do I really need it to be in array format? Perhaps there is another solution that can be used instead. Any ideas?
(function () {
'use strict';
function Query(selector) {
if (selector.indexOf('.') !== -1) {
selector = document.querySelectorAll(selector);
}
else {
selector = document.getElementsByTagName(selector);
}
[].push.apply(this, selector);
}
function $(selector) {
return new Query(selector);
}
Query.prototype = new Array;
Query.prototype.hide = function () {
for (var i=0,len=this.length; i<len; i++) {
this[i].style.display = 'none';
}
return this;
};
window.$= $;
}());