This line in my constructor function takes 0.15ms to execute.
[].push.apply(this, selector);
Please don't tell me 0.15ms time is acceptable. I am hoping there is some faster option.
Because I think this line is converting NodeList/HTMLCollection to array. I don't necessarily need to convert it to array. This is why, I think it can be replaced with something else. Can you think of?
(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.$= $;
}());