When trying the js backend, I often need to write objects that get compiled to 
js objects.

In javascript, it is frequent to make functions that accept a single object 
whose keys are interpreted as named arguments. One can pass a subset of the 
valid properties to mean that the rest are to be left default.

In Nim, if I have an object, say
    
    
    type Foo = object
      a, b: cstring
    

I can initialize only part of its properties, like this
    
    
    let foo = Foo(a: "hello")
    

This gets compiled to
    
    
    var foo = {
      a: "hello",
      b: null
    };
    

Notice that Nim always adds the `b` key, putting `null` as default. What I need 
is a way to obtain
    
    
    var foo = {
      a: "hello"
    };
    

This is for two reasons:

  * existing js functions may interpret that `null` as meaningful
  * sometimes I have very big objects (think of objects that hold all existing 
CSS properties) where only few keys are set at a time, and this may grow the 
memory usage significantly



How can one avoid to render missing properties in the js backend (short of 
writing an object type for any combination of keys, which is combinatorially 
infeasible)?

Reply via email to