« Java | Main | Music & Film »

Mon, Dec 04, 2006

ppk on iCab

Book Cover Peter-Paul Koch wrote a book on JavaScript that was published some weeks ago. It's good reading about developing compatible and standards-compliant JavaScript-based web applications that target different browsers.

Happily, it's one of the few JavaScript books that mention iCab. There's even a screenshot of iCab's "Identity" preferences in the section about browser detection (this section explains why browser sniffing never did and never will work correctly).

Posted by Thomas Much at 11:32
Categories: iCab & InScript, JavaScript

Sun, Oct 09, 2005

for..in vs. for each

JavaScript features for..in loops (enumerations) for a long time now. You can use it to easily enumerate all property names of an object. E4X (ECMAScript for XML, ECMA-357) specifies "for each" loops that enumerate the property values instead. So, where's the difference?

Consider the object

var obj = { lastName: "Much", firstName: "Thomas" };

The for..in loop

for (var i in obj) document.writeln(i + "<br>");

would yield

lastName
firstName

whereas the for each loop

for each (var i in obj) document.writeln(i + "<br>");

would display

Much
Thomas

To achieve the latter with a for..in loop, you'd have to write

for (var i in obj) document.writeln(obj[i] + "<br>");

Posted by Thomas Much at 22:09
Categories: JavaScript

JavaScript 1.6 - Array and String generics

The new JavaScript version in Firefox 1.5 introduces "generic" String and Array functions that can be applied on any object by simply calling the function on the String or Array constructor and passing the desired object as the first parameter. Since I could not find a list of all generic functions, I digged through the source code. Here's the result:

  • Array:
    concat, every, filter, forEach, indexOf, join, lastIndexOf, map, pop, push, reverse, shift, slice, some, sort, splice, unshift
  • String:
    charAt, charCodeAt, concat, indexOf, lastIndexOf, localeCompare, match, quote, replace, search, slice, split, substr, substring, toLocaleLowerCase, toLocaleUpperCase, toLowerCase, toUpperCase
Posted by Thomas Much at 21:27
Categories: Browsers, JavaScript

JavaScript 1.6 - Array extras

Firefox 1.5 comes with a new JavaScript version 1.6 that brings us some new Array functions.

As of release 182, InScript supports these new functions, too (check <inscript:settings()> to see if your iCab is built with a suitable InScript version). This release also has support for E4X's (ECMAScript for XML, ECMA-357) "for each" loops.

Posted by Thomas Much at 20:29
Edited on: Sun, Oct 09, 2005 20:30
Categories: Browsers, iCab & InScript, JavaScript