Mascara: Next Generation JavaScript compiler

Try it Download Buy About Documentation Blog Contact

Dynamic classes

In Classic JavaScript you can assign new properties to any object on the fly, or delete existing properties.

In ECMAScript 4 however, objects that at instances of classes cannot by default be modified during runtime. You can allow this by using the dynamic attribute on the class declaration.

dynamic class A {
    var b = 1;
}
var a = new A;
delete a.b;  // removes the property
a.c = 10;  // add new property 

Note that the type-checker cannot warn you if you access dynamic properties which might change or be deleted at runtime.

Built-in classes as Object, String etc. are defined as dynamic out of the box.

X Try!
Mascara JavaScript Generated JavaScript

Translating...
Show compiler settings