unpack

<script src="./point_src/unpack"></script>

Reasoning

to receive inline or dict based args - because inline is nice but unwieldy, as such - also allow dicts.

This allows for more complex options; later. Also then we can process inline args with a dict. And rearrange them later.

Meta Data
filepath_exists True
path unpack
filepath unpack.js
clean_files ()

  • VariableDeclaration
    const

    unpack

    =
    function ( args , defaults )
    Reasoning to receive inline or dict based args - because inline is nice but unwieldy, as such - also allow dicts. This allows for more complex options; later. Also then we can process inline args with a dict. And rearrange them later.
    read the args object into a dictionary (if required) use the `defaults` as as the defaults return an object. If args match an object, return with updates. one arg may be just a context. or an object of properties two args may be context and object. or context and prop let data = unpack(arguments, { otherPoint: undefined , color: undefined , width: undefined }) Note, proxies are slower than objects https://www.measurethat.net/Benchmarks/Show/6274/4/access-to-proxy-vs-object
  • VariableDeclaration
    const

    unpack0

    =
    function ( args , defaults )
    read the args object into a dictionary (if required) use the `defaults` as as the defaults return an object. If args match an object, return with updates. one arg may be just a context. or an object of properties two args may be context and object. or context and prop let data = unpack(arguments, { otherPoint: undefined , color: undefined , width: undefined }) Note, proxies are slower than objects https://www.measurethat.net/Benchmarks/Show/6274/4/access-to-proxy-vs-object
  • VariableDeclaration
    const

    NULLY

    =
    null
  • VariableDeclaration
    const

    runUnpack

    =
    function ( )
  • VariableDeclaration
    const

    callRunUnpackLarge

    =
    function ( )
    Use the runUnpackLarge
  • VariableDeclaration
    const

    assert

    =
    function ( expr )
    good
  • VariableDeclaration
    const

    runUnpackLarge

    =
    function ( ctx , sides , radius , fromCenter =True , color , width =1 , angle , open =True , close =True )
    This example receives many args. Same rules apply
  • VariableDeclaration
    const

    runUnpackArgsDefault

    =
    function ( ctx , otherPoint ={} , color =red , width =1 )
    Unpack with defaults from the args. But the args is still applied. return defaults (otherPoint, color, width) d = runUnpackArgsDefault(stage.ctx); apply/override a config d = runUnpackArgsDefault(stage.ctx, { color: 'green' }); extend defaults d = runUnpackArgsDefault(stage.ctx, { up: true }); Be careful of the above (for this args defaults), as `otherPoint` is recast as the given object, therefore the `{ otherPoint }` default return, will return the config object, not the first default property: # bad: const runUnpackArgsDefault = function(ctx, otherPoint={}, color='red', width=1) { let data = unpack(arguments, { otherPoint , color , width }) } # good: const runUnpackArgsDefault = function(ctx, otherPoint={}, color='red', width=1) { let data = unpack(arguments, { otherPoint: {} // altDefault , color , width }) }