Writing code to execute on yolpo
Style
Typical code which runs on yolpo look like this:
load('lodash.js');
a = _.map([1, 2, 3], function(n) { return n * 3; });
if (a[0] != 3) throw ''
if (a[1] != 6) throw ''
if (a[2] != 6) throw ''
This is 100% javascript, so there is nothing new to learn, but just a few things to point out.
- Use the load function to load synchronously an external javascript resource
- Think sequentially and make each statement as simple as possible
- Throw an exception if an expectation is not met
Global variables
Code which runs on yolpo has access to two global variables: load and waitUntil.
- function load(string url) - Loads synchronously an external javascript resource.
This function throws an exception (timeout) if the script is not loaded within 10 seconds.
- function waitUntil(boolean) - Holds the Process Counter (PC) until the argument becomes true.
Use this function to work on asynchronous API.