Small set of handy utility functions that is used at several ITSA modules.
With nodejs:
Create your project using this package.json. After downloaded, run npm install
and start writing your application:
In the browser:
For browser-usage, ITSA has a predefined loaderfiles. Once included, a global ITSA
object with default features is available. For customized loaderfiles, read: Customized build.
<script src="/itsabuild-min.js"></script>
The utility functions are all exported and accessable by their name. In ITSA-namespace, they are available as functions of ITSA.
Executes a function asynchronously, by placing it at the javascript eventstack.
ITSA.async(function() {
// do something
});
Executes a function asynchronously after a specific amount of time. It's alike setTimeout
combined with setInterval
, only those are buggy in some environments when you cancel the process. ITSA.later
is proven to work stable and returns a handler with a cancel
-method to cancel the request.
ITSA.later(function() {
// do something after 2 seconds
}, 2000);
ITSA.later(function() {
// do something periodic at 2 seconds
}, 2000, true);
ITSA.later(function() {
// do something after 2 seconds, then periodic at 5 seconds
}, 2000, 5000);
var handler = ITSA.later(function() {
// try to do something, but is happens to be canceled...
}, 2000);
handler.cancel();
Generator of unique id's. Can be prepended with a namespace. Will start with 1, but you can pass any value as start-value. Any following generator will start up from its last value.
ITSA.idGenerator(); // --> 1
ITSA.idGenerator(); // --> 2
ITSA.idGenerator(50); // --> 50
ITSA.idGenerator(); // --> 51
ITSA.idGenerator('jsonp'); // --> 'jsonp1'
ITSA.idGenerator('itsa', 10); // --> 'itsa10'
ITSA.idGenerator(50); // --> 50
ITSA.idGenerator('jsonp'); // --> 'jsonp2'
ITSA.idGenerator('itsa', 10); // --> 'itsa11'
ITSA.idGenerator(50); // --> 51
Table of Contents