Tag Archives: Object

JavaScript: Make a Real typeof

The problems with JavaScript’s typeof operator are manifold. It is so restricted, that its only use is in testing for undefined. The main culprit cause these restrictions is the loose typing together with the automatic type coercion: "2" + 2 results in 22, "2" == 2 is true, t = 2;typeof t returns "number" and t = new Number(2);typeof t returns "object" to name just a few.
The worst case is probably:

// somewhere on top of the code
var a = 2;
// some thousand lines and/or several scripts later
var b = new Number(2);
if(a === b){
    // CPR: Cardiopulmonary resuscitation
    console.log("Go on with CPR!");
} else {
    console.log("He's dead, Jim!"),

Continue reading


Adventures of a Programmer: Parser Writing Peril XVIII

The regular expression nagged me quite a bit until I got rid of it. updated this post to mirror my reflections, pardon, the changes (added at the end).

Last post I talked about using Tom Wu’s bigint library JSBN and the need to add some faster algorithms especially for multiplication. I just found out that I already did it đŸ˜‰ (needs some testing, of course, I haven’t even checked if it works at all).
But serious:
One of the thing needed for the front-end operator overloading is the backend operator overloading, because there is no way to do a useful operator overloading beside some fiddling with valueOf in ECMA-script. Continue reading