Hi. That last param is NOT for a “stopAnimation()” function, it is for a “whenAnimationHasStopped()” function.
It runs just AFTER the animation has automatically stopped.
The animation stops… based upon… how FAR we tell the mesh to rotate… in how many frames and at what speed.
Generally speaking, you cannot stop the animation. You must wait for it to complete.
When it completes… the “callback function” can tell you it has completed… and it CAN… tell another animation to start… often from a list of animations. In others words, has the previous animation in the list of animations… finished? If so… let’s run the NEXT one in the list.
Let’s stop right there… for now. Don;t worry about what SHOULD happen when the animationHasEnded function… and don’t worry about what that function is named.
Just KNOW… that the function… runs… WHEN animation completes BY ITSELF. It is NOT a stopper. 
I understand how this can be confusing… I was confused by it myself, for a long time.
Ok, lets go touring a simplified playground.
https://www.babylonjs-playground.com/#HH1U5#163
Two shapes… and two “overloaded” animation functions… spin() and spinTo()
They are quite different from one another. SPIN… uses a axis that YOU must set in the first parameter… and an amount of spin IN RADIANS (a float value, such as 3.14), and HOW FAST to do it, and I’ve also added another value… HOW MANY FRAMES to use to do the spin.
How many frames to use, and how fast… are very related, aren’t they. The older versions of spin (and spinTo) sort of LOCKED the number of frames… at 120. In THIS NEW playground… you can set the number of frames AND the speed.
(axis, radians, speed, frames)
\ \ \ \
"y" \ \ \
-3.14 \ \
125 \
120
box1.spin( "y", -3.14, 125, 120 );
-------------------------------------
Now for spinTo...
(unused, targetRot, speed, frames)
\ \ \ \
null \ \ \
new BABYLON.Vector3(0, -Math.PI/2, 0) \ \
125 \
120
box1.spinTo( null, new BABYLON.Vector3(0, -Math.PI/2, 0), 125, 120 );
Notice… that spin() uses an AXIS “y” and a radians 3.14 value… which is a FLOAT value.
Conversely… spinTo() uses NO axis (unused) and a vector 3 value… new BABYLON.Vector3(0, -Math.PI/2, 0) (which is NOT a float, it is a vector3). The vector 3 value… contains within it… WHICH axis… AND also how many radians (-Math.PI/2 or… -1.57 radians). Inside that vector 3, the -Math.PI/2 is stored in the Y segment OF the vector3. Again, the vector3 can store both WHICH AXIS, and HOW MUCH ROTATION.
The speed and the amount of frames… are used the same in both spin and spinTo. And again… previous versions of spin() and spinTo()… had no “frames” setting. It was locked at 120 frames. I allowed you/users to set it… in THESE two new versions. New power! 
Ok, this has surely blown your mind ALREADY.
But quickly here. you asked “how” are these animations “linked” or “associated” with the mesh.
ALL mesh… boxes, cylinders, spheres, all mesh… are sub-classes of BABYLON.AbstractMesh.
SO when we did this…
BABYLON.AbstractMesh.prototype.spin = function (axis, radians, speed, frames) {…
We actually “installed” a spin() function… on every subclass of BABYLON.AbstractMesh. In other words, we put a SPIN() function… on ALL mesh that you EVER create in your scene. Anytime you make a box, it has a SPIN() function automatically installed on it… because it was inherited from its “superClass”… BABYLON.AbstractMesh.
Don’t mistake this for parent/children. Think of it as… we changed the SPECIES. Box and cylinder automatically have a spin() on them… because we modified its bloodlines… and made it so ALL mesh (boxes, cylinders, everything) that has blood from BABYLON.AbstractMesh… now has the spin() function.
And then we did the same thing for spinTo(). We installed it on BABYLON.AbstractMesh… and so… it was handed-down to all “blood-kin”… which includes boxes and cylinders… as well as spheres, toruses, etc etc etc. ALL mesh… in your scene… have a spin() and spinTo() function… as soon as you create one or many. This… is called “overloading a class”. We didn’t modify the “parent”, we modified the “species” or “creature type”. Parenting and childing is a different thing… so don’t get THAT confused with overloading the type or species.
Heavy, huh? nod.
Notice that both spin() and spinTo() use the this keyword rather often. Every time the animation overload RUNS… this = the caller. When we called box1.spin()… this IS box1. When we call cyl1.spinTo()… this == cyl1.
And many times… for both of these animators… we asking the animator to spin FROM this.rotation (current rotation)… to some new rotation. Both of these animators… START at CURRENT rotation location… and then spin to somewhere else… at some speed and frames-rate.
So this… is the link to the mesh.
Let’s try an experiment. Let’s print “this”.name to console… each time an animation func is called/started.
We have 4 anim calls in the previous PG, with each call reporting to console… when it has finished.
This time… let’s print this.name… (the name of the mesh) at EACH anim-start time. Watch console…
https://www.babylonjs-playground.com/#HH1U5#166
I added line 5 and line 12… reporting the names of the mesh that are calling the funcs. We see that this is always the mesh that is calling the func.
I changed the “look” of the 4 animation calls… this time… too…making them less confusing-looking.
Look at lines 50, 54, 58, and 62. We are calling box1.spin and .spinTo… and cyl1.spin and spinTo… methods/functions… which do not exist on “normal” BabylonJS mesh. YOU added them to all BJS mesh (for your project only)… with line 2 and 9… the “overloads”. You reached deep into BabylonJS “core” and added a spin() and spinTo() feature… to ALL mesh in YOUR scene. You changed the species. 
Ok, your mind is surely completely “blown” (stirred-up crazy) and you likely have started growing a brain tumor. hehe. This might be why the experts say… “Hey, don’t use overloading… it just confuses everyone”. hehe. But it IS powerful. ALL the mesh you make in your scene… will automatically have a spin() and spinTo() method/function/feature on them. Ballsy and brave of you, isn’t it. You should feel powerful… and rightly so. You have used JavaScript Object Oriented Programming… via a special feature called prototypes. You have found a powerful wizard potion… and experimented with “first taste”. VROOOOOOOM!!!
I hope I have been helpful. You ask very wise questions… and they are NOT easy to answer… because class-overloading via prototypes… is an odd JS feature/power.
Overloaded animation functions like these… MIGHT NOT WORK for you… in the “long run”. Remember the “lists of animations” mentioned earlier? Now notice lines 34-36, and 44-46… the onThisMeshAnimEnded function for each mesh. Might be wise for you to change “on” to “upon”.
“uponThisMeshAnimEnded” … yeah I like that name better. You should change to that. 
Way at the end of line 6 and line 13… we see the “callbacks” being called… this.onThisMeshAnimEnded … and notice we are using the magical this keyword, again. Cool, huh?
ANYWAY… back to the lists of animations. The lists of animations need to be managed and updated… inside those onThisMeshAnimEnded functions. (or uponThisMeshAnimEnded if you rename them). It will require some special handling inside those functions… so you know WHICH animation in the list has finished, and which animation is the next one to start.
You might wish to overload cyl1 and box1… by setting… box1.lastAnimationStarted = 0; and cyl1.lastAnimationStarted = 0; … just after creating those mesh. You actually CREATE those properties by doing that. They did not exist on box1 and cyl1… before you did that.
But AFTER that… INSIDE the onThisMeshAnimEnded… you can check and increment that number.
this.lastAnimationStarted++; (increments the whichAnimation number).
I’ll stop there. But I think you can understand… that box1 and cyl1 COULD “carry with them”…which animation of a LIST of animations… was just now completed. And thus… you might know WHICH animation in some list of Anderson34-created animation calls… is the NEXT one. If cyl1 and box1 carry with them… WHICH was the previous from the list, you can determine which is the NEXT to call from the list. These lists of anims… would need to be invented by you, and would likely be an array of spin() and spinTo calls… a list… of animation “sequences”.
And it might not work as you expect… and might be a complete failure, because you might discover… that running little animation after little animation after little animation… might not give the results you wish. But maybe it will.
And maybe I need to stop talking RIGHT NOW, before my hands fall off and/or your brain explodes. Surely there are typos here, and me saying wrong things and teaching badly. I will try to “clean” this monster post over the next day or two. Be patient with me and yourself… this is some advanced stuff you are working-with, here. Again, try to find some time to study basic JS inheritence and prototyping, and please pardon the many incorrect things I could have told you. I am no pro at JS “OOP” or class prototyping…I just found it one day and made these goofy little animation utility funcs. They are probably bad idea… but they DO work and ARE handy… somehow.
Be well, my friend. Study slow… experiment a lot, and use lots of console.log reports to show yourself what is happening and help you learn. byeeeee.
Other helpers… feel free to clarify this mess, but don’t get brain tumors. 