Friday, May 4, 2018

Self-invoking

In my travails of yesterday, I did learn a few things.
I investigated whether "2", and 2 would be treated the
same:they would.


And today, I am still pondering the workings of a self-calling function. Below,
a +=counter example from W3 schools.

It looks complicated: 'add' is declared as a variable, but called as a function.
That's what it is. The stuff in parenthesis on the right of add is the self-invoking
function.

If we look at the simplest deconstruct at 3 (yellow), we see that storing
a simple function will only return 1, no matter how many times we click
to run add().

In the middle version (pink), we're venting: please return the function +=counter.
It does just that, return whatever comes after return...

(In blue). We need the syntax that wraps a bracket pair, and a parameter bracket pair with a
semicolon - to indicate an executable - around the whole: our self-invoking function.
Every time I click, the counter goes up by 1.



                                        *     *     *

Fine-tuned my random images scripts. I had to click a second time for the
very last tile to show; solved that. It's a countdown, not a countup. Works on a single click
this way.


No comments: