What is the difference between using call and apply to invoke a function?  var func = function() {   alert('hello!'); };   func.apply(); vs func.call();  Are there performance differences between the two aforementioned methods? When is it b...
I'm writing a Chrome extension that involves doing a lot of the following job: sanitizing strings that might contain HTML tags, by converting <, > and & to &lt;, &gt; and &amp;, respectively.  (In other words, the same as...
How do parseInt() and Number() behave differently when converting strings to numbers?...
What's the fastest way to count the number of keys/properties of an object?  It it possible to do this without iterating over the object?  i.e. without doing  var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) count++;   (Firefox did...
I've recently read the Yahoo manifesto Best Practices for Speeding Up Your Web Site. They recommend to put the JavaScript inclusion at the bottom of the HTML code when we can.  But where exactly and when?  Should we put it before closing </h...
A previous poster asked Function.bind vs Closure in Javascript : how to choose?  and received this answer in part, which seems to indicate bind should be faster than a closure:     Scope traversal means, when you are reaching to grab a value   (var...
I was asked recently what was the most efficient way to reverse an array in Javascript. At the moment, I suggested using a for loop and fiddling with the array but then realized there is a native Array.reverse() method.  For curiosity's sake, c...
I read here (Douglas Crockford) using prototype operator to add methods to Javascript classes saves also memory.  Then I read in this John Resig's article "Instantiating a function with a bunch of prototype properties is very, very, fast...
With a JavaScript Array, I can reset it to an empty state with a single assignment:  array.length = 0;   This makes the Array "appear" empty and ready to reuse, and as far as I understand is a single "operation" - that is, constant...
For some algorithm I was writing recently I thought that a hash would be excellent. I thought that I could probably just use the member variables in an object as key value pairs. I am not sure if this is optimal since I don't really know what i...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.