Advertisement
Guest User

RE: words calc script

a guest
Jul 17th, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Hi <name removed>,
  2.  
  3. Thanks for your message, I've fixed the problem, and updated the post at http://stackoverflow.com/a/7451243/938089.
  4.  
  5. The bug in IE was caused by the way how the initial array was initialised:
  6.  
  7. var keys = [,];
  8.  
  9. This creates an array with length 1, containing zero elements. The concept behind it: The first element (at index 0) does not contain any meaningful value for the application. To avoid (accidental) (mis)use of this element, I choose a value which cannot be accessed without triggering an error. Other methods to create an array with such behaviour is:
  10.  
  11. var keys = [null];
  12. var keys = [void 0];
  13. var keys = [undefined];
  14. var keys = new Array(1);
  15.  
  16. [According to the ECMAScript 5 specification][1], the length of an array created using [,] must be 1, because there's no element following the last comma within the array literal ("If an element is elided at the end of an array, that element does not contribute to the length of the Array.").
  17. In IE8 and before, the length is 2, as shown by the expression [,].length. That's incorrect, and a vendor bug (it's fixed in IE9). The solution is to use one of the four alternatives I proposed.
  18.  
  19. Regards,
  20. Rob W
  21.  
  22. [1]: http://es5.github.com/#x11.1.4
  23.  
  24. ----------
  25. In response to:
  26.  
  27. > Hello, Rob, I've just found your cool script http://jsfiddle.net/nkPBU/,
  28. > for IE8 it doesn't work - shows error:
  29. >
  30. > Webpage error details
  31. > User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.2)
  32. Timestamp: Tue, 17 Jul 2012 12:17:19 UTC
  33. > Message: '1' is null or not an object
  34. > Line: 53
  35. > Char: 5
  36. > Code: 0
  37. > URI: http://fiddle.jshell.net/nkPBU/show/
  38. >
  39. > I tried to fix it but failed, I'd really appreciate if you can suggest smth.
  40. >
  41. > Thank you in advance,
  42. > <name removed>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement