basiljs/basil.js

Why do we have some Vector methods twice? (static method)

trych opened this issue · 2 comments

trych commented

We have the methods Vector.dist(), Vector.cross() and Vector.dot() twice in our code.

I think this is intentional, however, can someone help me understand how this works?

Example dist:

We once have it as a method of the Vector prototype:

Vector.prototype = {

// ...

dist: function(v) {
      var dx = this.x - v.x,
        dy = this.y - v.y,
        dz = this.z - v.z;
      return Math.sqrt(dx * dx + dy * dy + dz * dz);
    },

// ...

}

and then we have it as a Vector method, outside the prototype thing:

  Vector.dist = function(v1, v2) {
    return v1.dist(v2);
  };

@basiljs For the second version it says, it is a "static function" (quote: "Is meant to be called "static" i.e. Vector.dist(v1, v2);"). I don't know what that means. What is a static method?

Also, I guess the second version does not overwrite the first version, right? I guess it extends it somehow? Is the first version supposed to be private?

Also, I think this turns into a problem that the inline docs of one version are overwriting the other one. How should we handle that? Should we rename one of them?

b-g commented
trych commented

Ah, okay, I get it now.
Then I am just confused about the documentation. We should probably have that only in one place and then give examples for both syntax variants, right? @fabianmoronzirfas