How:Write scripts in JavaScript for Memento: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
Line 67: Line 67:
A library can have any number of trigger scripts, of action scripts, & of custom data source scripts. If there are things you do repetitively in scripts, you can put them in a shared script, and they will be available to any other script that runs.
A library can have any number of trigger scripts, of action scripts, & of custom data source scripts. If there are things you do repetitively in scripts, you can put them in a shared script, and they will be available to any other script that runs.


For instance, trigger scripts are the most often used type of script, and in trigger scripts, it is very common and common practice to define a variable e to contain the current Entry object — var e = entry(). Then, you can say e.field() instead of entry().field. This not only saves keystrokes & makes the code more readable, but also runs a bit faster, because the entry() function is run only once in the script. This might be the first thing you'd think of to share. Of course, entry() is not called at all in library action scripts, for instance, so e will not be used in such scripts, but it doesn't hurt much at all, so it's OK that the code is shared also to these scripts.
For instance, trigger scripts are the most often used type of script, and in trigger scripts, it is very common and common practice to define a variable e to contain the current Entry object <code>var e = entry()</code>. Then, you can say <code>e.field()</code> instead of <code>entry().field()</code>. This not only saves keystrokes & makes the code more readable, but also runs a bit faster, because the <code>entry()</code> function is run only once in the script. This might be the first thing you'd think of to share. Of course, <code>entry()</code> is not called at all in ''library'' action scripts, for instance, so <code>e</code> will not be used in such scripts, but it doesn't hurt much at all, so it's OK that the code is shared also to these scripts.


== Trigger script ==
== Trigger script ==

Navigation menu