Posts

Showing posts with the label make

TaskSpeed - The Real Cheat

Inline "make" test that no library should " outperform " - this is a reply to this post which has few good points, we all know about browsers VS SunSpider, and other tests, but it falls down when it criticizes the TaskSpeed aim which is completely different. "make": function(){ for(var el = document.createElement("div"), outperform_this = [], i = 0, length = 250; i < length; ++i ) outperform_this[i] = '<ul class="fromcode" id="setid' + i + '"><li>one</li><li>two</li><li>three</li></ul>' ; el.innerHTML = outperform_this.join(""); for(var i = 0, fragment = document.createDocumentFragment(), childNodes = el.childNodes; i < length; ++i) fragment.appendChild(childNodes[0]) ; document.body.appendChild(fragment); if(document.querySelectorAll) return document.querySelectorAll(...

A fast and crossbrowser function to make an Array

An absolutely common task present in almost every library, is to transform a generic collection/list of objects or DOM Elements into a friendly Array. Cases Scenario It is possible to apply directly an Array.prototype.slice call to quickly return an Array It is not possible at all apply every kind of Array prototype to the list Cases scenario detection When we execute a piece of JavaScript in a web page, we can assume that we have at least one DOM element in that page, as the script itself for example, so it is always possible to obtain a collection of elements calling document.getElementsByTagName("script") or a generic ("*") in this case probably superflous considering the latter assumption. Cross browser and fast makeArray proposal var makeArray = function(push, slice){ try{ // Andrea Giammarchi proposal slice.call(document.getElementsByTagName("script"), 0); return function(array, results){ array = array instan...