Mascara 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 Mascara however, objects that at instances of classes cannot by default be modified at runtime. This allows stronger static guarantees.

But you can explicitly allow dynamic objects 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.