previousnext

In javascript, objects can be modified by modifying their prototype. The code below, including the library, is completely equivalent to the code of the previous section. All I did was to remove (by commenting it out) a method definition from function Ball in the library and add it via a modification of Ball's prototype inside the code tab.

In the future, when we want to modify parts of the library code, we will sometimes use this trick of extracting only the part we need and working on the class prototype.

Experiment!

First, verify that the code works as before. Afterwards, if you have not done so previously, try to incorporate the collision detection inside the move() method; this is what we will do (and more) in the next section.

previousnext