Writing Javascript¶
As we have learned while creating “Hello, world!” addon, Javascript part of addon is given in separate .js
file and looks like:
This is a typical structure of Javascript part - let’s learn how it works.
Addon initialization¶
.js
file should contain single top-level function - in our example it is named init
, but it can have any other or no name at all. It is run when addon is applied to target page.
This function creates and enclosures all the addon logic but does not launch it yet. In our example, single function doWork is defined.
Instead, it returns an object (addonEntry
in our example) that contains another function in its field start
.
Addon launch¶
The start
function actually launches the addon - in our example it calls doWork
.
Arguments of start
function:
taistApi
is an object that provides access to all Taist features. All the features are described in other chapters of this guide. IndoWork
we see use oflog
function - it’s a preferred way of Debug output.entryPoint
is used for fine-tuning of what addon parts to launch on what pages of target site.