phetsims / twixt

Animation library for interactive HTML5 graphics
MIT License
1 stars 3 forks source link

why is Easing a type? #24

Open pixelzoom opened 5 years ago

pixelzoom commented 5 years ago

Easing is currently a collection of static methods and constants. It's constructor does nothing and it has no state:

  function Easing() {}

Why is it a type?

jonathanolson commented 5 years ago

I had it as a type because it essentially defines three abstract methods. I'm open to recommendations for changes.

Should it take the 3 methods as constructor parameters? Should it just be POJOs and the method documentation could be moved to the top of the file?

pixelzoom commented 5 years ago

This is a bizarre pattern you're using here. You have an abstract base type. You instantiate that abstract base type, which is antithetical to the whole notion of "abstract". Then you morph the abstract instances into concrete instances using assignment. And if I were to inspect instances of Easing in the debugger, they are liable to have different implementations of the abstract methods.

I'll leave it up to you to decide whether or not to change this.

jonathanolson commented 5 years ago

I agree it's a bit weird, and I'm happy to change it. What would you recommend instead?

pixelzoom commented 5 years ago
  function Easing( value, derivative, secondDerivative ) {

    // @public (read-only)
    this.value = value;
    this.derivative = derivative;
    this.secondDerivative = secondDerivative;
  }