Monday, December 01, 2008

Chrome Beta Breaks Internet? #chrome

I hate programming UIs in browsers, I'm sure everybody does. With Google's Chrome browser another headache is born. Chrome's JavaScript Engine V8 implements ECMAScript-262, but not with some of the features that come in JavaScript v1.6 and are implemented by FireFox. One example is the "for each in," not that this is implemented correctly in Internet Explorer.
var query = "plaap=poekoe&hi=hello";
var valPairs = query.split('&');

for each (var pair in valPairs) {
Uncaught SyntaxError: Unexpected identifier
        var tempPair = pair.split('=');
There is a solution for this I found on the Mozilla Developers Center: forEach, with this you are able to implement a callback that cycles throught the Element.

if (!Array.prototype.forEach){
  Array.prototype.forEach = function(fun /*, thisp*/) {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
      if (i in this), this[i], i, this);

Technorati technorati tags: , , , , , , ,