I have found the problem! Thank you Kevin, your questionning helped me to figure it out.
All I needed was to replace this:
- return methods[method].apply(this, Array.prototype.splice(arguments, 0, 1));
With this:
- return methods[method].apply(this, Array.prototype.splice.call(arguments, 0, 1));
Actually I took this line from the
jQuery plugin authoring page, but of course i miscopied it.
"Arguments" in javascript is kind of a keyword that gives you all the current scope arguments as an array,
but it is not an array, it just has an indexer. You can't call directly the javascript array functions on it. Instead you have to cheat by calling them from the array prototype. I just forgot the "call" word, and the arguments sent to apply were an empty array.
If you look at my code closer (the last lines of javascript) you'll see that the Start button was calling init which is the default method, and all the arguments were passed without splicing the array, hence the no bug.
The big question is : why for the reset method, which does not take arguments anyway, this bug was triggering, and why only on the second call??? Javascript ways are instrutable...
Here is the
corrected code.