Tag: JavaScript

Traceur on JavaScript Jabber

Last week the interview with me on JavaScript Jabber went live. The interview is a about Traceur but we also ended up talking quite a bit about ES6.

JavaScript: Muddy Waters of Reflection

Just like a lot of other people I have a love-hate relationship with JavaScript. I love how expressive it is and I love that it runs everywhere but there are also some things where the languages falls very short. The gripe of the day is how JS makes reflection part of the everyday programming flow. ...

Iterating over Harmony Maps

A while ago Chrome got some JavaScript Harmony features (behind a flag). One of these features is the new Map “class”. The current implementation does not provide a way to iterate over the keys or values because that depends on Harmony iterators which are not yet implemented in V8. However, we can create our own ...

Proxies

V8 currently implements the same Proxy API as Firefox. The API for proxies has changed a bit since then so be extra careful when testing this. Proxies are a very low lever construct. The are very powerful and they allow an object to intercept any access to its properties as well as intercept things like ...

typeof null

In ES5 typeof null evaluates to 'object'. This quirk was one of the changes we wanted to fix in ES5 but at the time we agreed that we did not want any semantic changes. With Harmony there will be a way to opt in (TBD) so when you opt in we can now provide a ...

Block Scope

Did you know that ES5.1 does not support function declarations inside blocks? Browsers do allow it but they do not agree on the semantics. For ES Harmony we are specifying the semantics for functions inside blocks. Functions inside block use let scope, which means that they are limited to the current block scope. function f() ...

Harmony Collections

Simple maps and sets allow you to create a Map with an object as the key. Normally people use Object.create(null) as a map but that limits the keys to strings. The Set constructor is similar and it allows a set containing objects. Neither of these currently support a way of iteration since iteration is planned ...

JavaScript Harmony in Chrome

We recently added a way to turn on JavaScript Harmony features in Chrome. If you have a Canary or a recent Developer Channel build of Chrome you can turn on some Harmony features from chrome://flags. You need to manually enter that address in your browser. Look for an entry called “Enable Experimental JavaScript” The following ...

Inheritance Antipattern

Michael Bolin wrote an excellent blog post about the inheritance antipattern that is gaining a lot of foothold among JavaScript developers these days. The post also links to an article giving a lot more depth on the topic. When I attended The Ajax Experience 2009, I saw a number of “misguided” things that people were ...

Closure

Today we finally announced and released Closure (or Closure Library as the JS library is officially known as). History Me and Dan Pupius started the JS library at Google a long time ago. At the time there was a lot of good JS code at Google but there was really no order to it and ...

EcmaScript Edition 5 is final

After a lot of back and forth in the TC and the failure of ES4 the TC was focused on ES3.1. The final spec for ES3.1 is now called EcmaScript, Fifth Edition. The most exciting thing in ES5 is that it finally standardize getters and setters. It also allows us to control the enumerability as ...

New Explorer Canvas Release

Over at the newly created Explorer Canvas Blog we announced the new release.

Using catch-alls to implement super in SpiderMonkey

Another thing that always been bothering me about OOP in JS is that calling super is such a pain. Some libraries do ugly hacks like checking the source (by calling toString on their constructor and method function objects) and then wrap the original function in another function that encapsulates a variable called super. Other libraries ...

Instance private, class private, package and friends

Update: This is flawed. See details at the end. This post was inspired by a post that Robert Nyman wrote a while back. At the same time I was thinking about how to achieve private fields without the memory issues. JavaScript does not have private members as understood by a lot of other object oriented ...

IE8 and box-sizing

One of my top feature request for IE8 was for it to support box-sizing. I’m happy to see that IE8 does support box-sizing although it has a annoying quirk. The DOM property name is not correct. The rule for translating CSS property names to DOM property names is to replace a dash followed by a ...

The Good, the Bad and the Ugly

The Good Attribute handling in the DOM is finally working. MS said that this was one of the hardest things to fix and yet they did it. hashchange events simplify history management. I wish they implemented more of the HTML5 proposals when it comes to history state management but getting an event when the hash ...

JScript 5.7

[Revised to not sound as nagging as I always sound] The JScript 5.7 patch is now being pushed to an IE6 computer near you… IE6 uses Jscript 5.6 which has some design flaws when it comes to garbage collection. This is just a small issue for small applications but it is a large issue for ...

RegExp Tool

My favorite text editor of all time is ActiveState Komodo. I used to use the full/pro version of this but since I was too lazy to buy it so I kept redownloading the trial version every month. A while back ActiveState released a free version of the editor called Komodo Edit. Komodo Edit has almost ...

New Explorer Canvas Release

We finally got our act together and squashed some long standing bugs. This is the first bug fix release since we initially release ExCanvas over a year ago. Support for sub pixel rendering Crop content if painting outside the canvas initElement now returns a reference to the fixed element Fixes to arc Printing support Implement ...

Tamarin

I guess you all heard that MacromediaAdobe donated their JIT compiler version of JavaScript to Mozilla. Tamarin is the JIT for Action Script 3 (AS3) which is a version of ECMAScript 3rd Edition. Using a JIT should improvement of JavaScript by at least 10x. This is of course very good news. However a lot of ...

Associative Arrays Must Die

Andrew Dupont wrote an excellent post explaining why using Array for maps/hashes/asssociative arrays are considered harmful. If you use Arrays for hashes in JavaScript you should be ashamed of yourself

Going to Ajax Experience

I’ll be standing in the Google booth at the Ajax Experience conference on Friday afternoon. I guess it is time for me to figure out what all this Ajax hype is all about.

appendChild is not a Function

Another day another rant. Now it is time for me ranting how bad IE DOM/COM objects and ActiveX objects integrate with JScript. Given: var f = document.body.appendChild; f.call(document.body, document.createTextNode('Huh?')); This throws an exception because DOM/COM methods are not really instance of Function. Why is this an issue you might ask? Assume we have an ActiveX ...

IE 7 DOM and JS Changelog

Here are the DOM and JavaScript changes in the latest version of Internet Explorer 7, as well as the planned ones for the final release, since Internet Explorer 6.0 which was released in 2001: Begin Changelist ----------------- ----------------- End of Changes

WebOS in the News

In 1999 I was working at a company called WebOS that was doing a window environment and application platform that run inside the browser using techniques that nowadays people refer to as Ajax. It seems like it is time for companies to try the same concept again. Ars Technica and ZDNet are covering YouOS (which ...

6 Months at Google

Maybe my little April fools joke was a bit too obvious. Me leaving Google for Microsoft? That would never happen. I don’t think anyone ever left Google for Microsoft and there is a reason why. Google is just awesome. At Google I got to work with the smartest people and they have all of the ...

ExplorerCanvas

Over the last few months, me, Glen and Emil have been working on an open source version of canvas for Internet Explorer. The implementation uses VML and IE style filters (for image rotation, rgba and globalAlpha). It implements most of the specification but some areas are a not implemented (for example composite drawing, patterns, radial ...

JS Generics

With JavaScript 1.6 Mozilla introduced generic version of a lot of the Array and String methods. Without broad support these very useful methods are in reality only available to Firefox and Firefox extension. Personally I’ve become too used to them to survive long without them. I’ve previously posted the JS 1.5 array extras and I’ve ...

Don’t trust this guy

I was reading through an article about Atlas at eWeek where they quote Russ Nemhauser, head of Nemhauser Media Inc.: “JavaScript is not an object-oriented language. It does not have strong typing; there is no exception handling; and there is no inheritance. One of the biggest problems with the AJAX approach is the amount of ...

IE7b2, is it intentionally this bad?

Here are just a few things that are incorrect, horribly broken or totally non-existent in Internet Explorer Beta 2. (This is far from a complete list. I’m assembling this list as I’m writing this post.) DOM Level 1 Core Comments are still incorrect Attributes are still horribly broken DOM Level 2 Views document.defaultView getComputedStyle getOverrideStyle ...

Emil is on Fire

Emil has been really active lately. Not only did he emulate canvas in IE, he also used it to create a slick charting control for WebFX. On my end: Google is really awesome, San Francisco is the best city ever and my girlfriend is super sweet.

Go Glen

This is what Glen Murphy has been working on since he started at Google.

The W3C’s Response to HTML5

So it seems that the W3C are finally realizing that XForms and SVG 1.2 is not going to replace the web. Today they annonced the Web API Working Group which is basically doing exactly what the WHATWG has been doing for more than a year. I really hope that no one is reinventing the wheel ...

Atlas Comments

Last night I looked a bit at Atlas and its Quick Start tutorials. With the risk of sounding like I hate Microsoft I’ll write down some thoughts… Atlas is nice. I really like a lot of it. There are tons of things that I don’t like but the initial reaction is that this might end ...

IE7 and XMLHttpRequest

Over at the IE Blog: IE 7 implements a native XMLHTTPRequest object for Javascript applications, instead of requiring an ActiveXObject to be created. This also means XMLHTTPRequest will function on machines that have ActiveX disabled. Thank you Dean.

JavaScript 1.6

With the upcoming release of Firefox 1.5 Mozilla have decided to increase their JavaScript version number to 1.6. There are basically three new features since 1.5: ECMAScript 4 XML Array Extras Array and String generics Array and String generics means that some of the methods that are available on Array.prototype and String.prototype are now also ...

For Each Loop in Mozilla

I’m not entirely sure when Mozilla started to support for each loops but I guess it was part of the E4X code checkins. Anyway, I was totally shocked when I saw it and I fired up a quick test. var o = {a: "A", b: "B", c: "C"}; for each (var v in o) { ...

Ajax is so 1999

Like you didn’t know that already? Scott Isaacs from back in 1997 has a series going at his blog. Scott is one of the original DHTML guys and he wrote useful stuff when most other people were stuck on animating layers. He is also one of guys behind DOM level 1. Well worth a visit ...

JScript Object Memory Leak

We all know that the memory leaks in Internet Explorer are horrible. However we’ve found ways (often making beautiful code really ugly) around these issus. My general guideline has always been to make sure that you don’t keep any reference betwen JScript objects and DOM/COM objects (and the other way around) as well as make ...

Some Real IE7 News

I guess you all seen and maybe even tried Internet Explorer 7 Beta 1 by now. To me it wasn’t very surprising. Dissapointing? Yes. Well, according to Chris Wilson, the following bugs have already been fixed and we’ll see them in beta 2: HTML 4.01 ABBR tag Improved (though not yet perfect) <object> fallback CSS ...

Screen Readers Suck

There has been some mumbling about accessibiliy and javascript for quite some time now and today I read the following at the DOM Scripting Task Force blog: It’s also all but impossible for some applications, such as Google Maps. In fact, after some preliminary testing our own Derek Featherstone was so dismayed by the state ...

DOM Scripting Task Force

I guess you’ve all seen the DHTML… ehmm… DOM Scriptiping Task Force over at The Web Standards Project by now. It’s about time someone realized that DHTML is not just An outdated scripting technique that is mainly characterized by the changes it makes to the style properties of certain elements, and by the use of ...

JS: The Good, the Bad and the Ugly

An article comparing JScript and VBS got me some ideas about what I think should be added to JS 1.6. Date I like the Date object in JS but it needs a lot of improvements. These following things are really missing: Localized weekday name Localized month name Week start day Week number (localized because it ...

And and Or in JS

The logical and (&&) and the logical or (||) are two really useful operators in JS. The following holds true: a || b results in a if Boolean(a) == true, otherwise b a && b results in b if Boolean(a) == true, otherwise a Using this one can often simplify expression a lot. For example: ...

MSE – Microsoft Script Editor

Microsoft Script Editor is probably one of the lesser known tools that can really make a difference when it comes to developing web applications. MSE is a debugger, much like Visual Studio and it comes bundled with Microsoft Office. It should not be mistaken for Microsoft Script Debugger which is a piece of crap compared ...

DOMParser for IE and Safari

A few days ago Dave over at the WebGraphics blog posted about how to parse a string into a DOM tree for Safari. I commented “How about implementing the DOMParser object in js?” and before I knew it I did it myself and adding IE compatibility on the way: if (typeof DOMParser == "undefined") { ...

XSLT in JS

I know this one is not too new but is still very interesting. Steffen Meschkat has created an XPath, XSLT and DOM engine written in pure javascript. Steffen works for Google and I believe this excellent piece of code was written in his 20 percent time to allow Opera and Safari to work with Google ...

Updated Live Search

I took the time to update the Google Live Search Greasemonkey script a bit to make it a bit more defensive. While I was messing with I also added code to update the links above the search field to go to the search terms that the last result used (instead of the search term the ...

Google Live Search

This is a script for Greasemonkey that modifies the Google search page to make the results show up as you type. Steps to install: Install Greasemonkey Once that is done you can right click the following link and select Install User Script…: googlelivesearch.user.js The Details When the user types in the search field the browser ...

Object.prototype is verboten

It is not seldom that you see people messing with Object.prototype. This is very bad because it breaks the object-as-hash-tables feature in javascript. Basically, the following is a very common scenario: var obj = {a: "A", b: "B", c: "C", d: "D"}; for (var key in obj) { doSomething(key, obj[key], obj); } if ("b" in ...

Array Extras

With the upcoming Firefox 1.1 release (and other browsers based on Gecko 1.8) things are starting to move in javascript land. During the early years of javascript a lot happend but then came the ambitious plans ofJS2 and the improvements to js just kind of died away for no reason. It seems Mozilla is finally ...

The List

Emil reminded me of Joel Spolsky’s list of things that cannot be well done in a web application Create a fast drawing program Build a real-time spell checker with wavy red underlines Warn users that they are going to lose their work if they hit the close box of the browser Update a small part ...

Client Side Real Time Spell Checker

I knew Emil was playing around with a real time spell checker written in DHTML and it got me very excited. This is probably a big milestone in our field and now that he let the cat out of the box I cannot express my amazement over the talents that this guy has. See the ...

JS, Encoding and XMLHttpRequest

I run into a quite strange issue today. Basically the problem was that a javascript file was encoded using ISO-8859-1 and contained some weird characters. It worked fine in a plain HTML script tag that included the external file. However it did not work when the file was loaded using an XMLHttpRequest (MSXML has exactly ...

Errors and AJAX

XML.com has an article called Errors and AJAX where they suggest that client side errors should be reported back to the server for logging. This sounds a bit familiar to me. Me and Emil did the same thing back in 1999. I guess it all comes back around sooner or later.

Ecma Script Template Engine

Lately, I’ve been feeling quite creative. I guess I can thank World of Warcraft for that. Or actually the other way around. I got out of my addiction after a week in USA and I decided that I would not touch it again. Lately I’ve been looking at simpler ways to output data received from ...

playground/tunage

Since I’m now a proud musikCube user I thought I would use one of its nice feature, called Tunage, to display the currently playing song here on my weblog. It sounded fun and most importantly small enough to do in a few hours. I had a pretty clear view of what I wanted in the ...

Without the with statement

The with statement is a powerful programming concept that Microsoft added to JScript because it was already in VB and VBScript. It later became part of ECMAScript because one of the major players had it. The with statement allows you to reference fields in an object without prefixing the field. var x = 100; document.body.style.left ...

I guess I Got Foo

Foo blogged about him trying to convince me to start my blog…. I guess I owe it all to him then Seriously though if we had not had our chat on Saturday I would most likely not have gotten this shit done. While you are at his place you really should check out his Outlook ...