Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trych opened this issue Apr 13, 2018 · 2 comments
Open

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

trych opened this issue Apr 13, 2018 · 2 comments

Comments

@trych
Copy link
Contributor

trych commented Apr 13, 2018

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
Copy link
Member

b-g commented Apr 16, 2018 via email

@trych
Copy link
Contributor Author

trych commented Apr 17, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants