standardize watch feature

Jeff Watkins jeff at metrocat.org
Tue Dec 29 04:55:44 PST 2009


On 27 Dec, 2009, at 6:12 AM, memolus at googlemail.com wrote:

> https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference:Global_Objects:Object:watch
> 
> I really do need it for my Modell-View-Controller application. If
> didn't had it, I had to use

That's funny, I didn't need it when I wrote the Coherent MVC library. There's no explicit call to update the UI, it's all achieved through the magic available in ES3. ES3! Not the goodness of ES5. (After all, it still has to work in IE.)

> modell.doSth();
> modell.x++;
> modell.save();
> 
> where modell.save() will call the controller to reload all properties
> into view. With the watch feature I'm saving the last line. Property
> changings on the modell affects the view instantly.

Now, you'll only be able to detect changes to raw properties on ES5 browsers, because IE doesn't support getters and setters, yet. But if you're willing to recraft your code to look like the following:

    model.doStuff();
    model.setX(model.getX()+1);

You'll be just fine on ES3 browsers.


More information about the es-discuss mailing list