Naked Javascript

Long ago, I ran across an idea called Naked Objects Once I started working with Javascript, it occurred to me that it’s object enumeration model might make something like that fairly easy. Thursday, with a partially fevered mind, I built something of a proof of concept, though it barely deserves even that title. Right now it is really a very simple browser; key missing features include the ability to edit properties, execute methods, and persist the resulting state. There are also a number of more insidious problems with Javascript itself.

DontEnum

Javascript has the ability to enumerate the members of an arbitrary object, however some of the system methods don’t show up. This is useful so, i.e., the splice method doesn’t show up when you iterate through an array. Of course this breaks rather badly anyway when you try to add you own methods to arrays, only have them show up as items in every array. In any case, in order to expose these operations on system objects, I’d have to hard-code a list of all the DontEnum properties. And come Javascript 2/ECMAScript 4, DontEnum becomes available to users, so complete browsing is totally hosed.

Is there a MOP in the house?

I’m only part way through The Art of the Metaobject Protocol, but I think I’ve got the main message. By exposing key parts of the object system’s implementation, it becomes possible to implement features like Smalltalk’s browsing editor. Javascript falls down on at least two accounts here – DontEnum, above, and the fact that there is no standard way to discover the prototype object.

Dynamic Typing

Property editing and specifying function parameters would be greatly enhanced by being able to use appropriate editors for the data required – but Javascript is a dynamically typed language; I might be able to look at the current type for limited use with properties, but function parameters are a lost cause without some kind of custom annotation.

Posted Saturday, February 2nd, 2008 under Devlog.

One comment so far