How to call a static function from an instance or from a member function, in JS console

#1

If you try to call a static method from an instance of an object, you’ll notice that the number of arguments accepted by the method defined on the object is reduced by one. How can you call the static method on the type of the object?

Here’s a console snippet:

> var a = FixedAsset.make()
undefined
> a
{children: Array(0), denormParents: Array(0), denormChildren: Array(0), assetOwners: Array(0), orgs: Array(0), …}

> a.generateNewIds
ƒ anonymous(count
/*``*/) {
  if (arguments.length > 0)
    throw new C3.typesys.Error('Member function "generateNewIds" on FixedAsset takes no arguments.', "InvalidInputParam");
  return this.type()._…

But c3ShowType(FixedAsset) shows that generateNewIds(count) takes one argument.

#2

I ran into this problem earlier today, and fixed it by calling a.type() to get to the Type, where you can call the static method.

So, if you wanted to call FixedAsset.generateNewIds() from a (rather than from FixedAsset itself), you would do

a.type().generateNewIds(count)

I believe this is a result of the implementation details of static vs. member methods in C3 Types. It must be that calling a static method on an instance automatically passes the instance as the first argument to the method. Note that this is a bit different from other programming languages.

> var a = FixedAsset.make()
undefined
> a
{children: Array(0), denormParents: Array(0), denormChildren: Array(0), assetOwners: Array(0), orgs: Array(0), …}
> a.generateNewIds  // This is a static method that should take 1 argument
ƒ anonymous(count
/*``*/) {
  if (arguments.length > 0)
    throw new C3.typesys.Error('Member function "generateNewIds" on FixedAsset takes no arguments.', "InvalidInputParam");
  return this.type()._…
> FixedAsset.generateNewIds  // This correctly takes 1 argument
ƒ anonymous(count
/*``*/) {
  if (arguments.length > 1)
    throw new C3.typesys.Error('Function "generateNewIds" on FixedAsset takes one argument.', "InvalidInputParam");
  return this._call("generate… 
> a.type().generateNewIds  // This works too
ƒ anonymous(count
/*``*/) {
  if (arguments.length > 1)
    throw new C3.typesys.Error('Function "generateNewIds" on FixedAsset takes one argument.', "InvalidInputParam");
  return this._call("generate…
> a.unremove  // This is a member function that takes no arguments
ƒ anonymous() {
  if (arguments.length > 0)
    throw new C3.typesys.Error('Member function "unremove" on FixedAsset takes no arguments.', "InvalidInputParam");
  return this.type()._call0("unremove", …
> FixedAsset.unremove  // the member function defined on the Type
ƒ anonymous(this_
/*``*/) {
  if (arguments.length > 1)
    throw new C3.typesys.Error('Function "unremove" on FixedAsset takes one argument.', "InvalidInputParam");
  return this._call("unremove", { "…