phetsims / hookes-law

"Hooke's Law" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
1 stars 4 forks source link

Public function setPincersOpen could be moved to the inherit block #12

Closed jessegreenberg closed 9 years ago

jessegreenberg commented 9 years ago

The setPincersOpen() function in RoboticArmNode is declared as a public function inside the RoboticArmNode constructor. Should setPincersOpen() be added to the prototype through the inherit call?

    /**
     * Open and close the pincers
     * @param {boolean} pincersOpen
     */
    this.setPincersOpen = function( pincersOpen ) {
      topPincerOpenNode.visible = bottomPincerOpenNode.visible = pincersOpen;
      topPincerClosedNode.visible = bottomPincerClosedNode.visible = !pincersOpen;
    };
pixelzoom commented 9 years ago

My initial rationale for creating setPincersOpen in the constructor was that there will only be 4 instances of RoboticArmNode in the sim, so there is minimal size penalty for adding it in the constructor. And by adding it in the constructor, there were 4 fields (nodes) that could be kept private. But I can see how this is confusing, so I've moved it to the prototype.

Back to @jessegreenberg for review.

jessegreenberg commented 9 years ago

I see, that makes sense. This looks great though, thanks! Closing.