Getting started with JS.Class
You can use JS.Class on any of the supported platforms without any custom configuration. To start using JS.Class in your project, you’ll need to download it using the link on the left.
If you’re using JS.Class on Node and do not need to support other environments,
you can install it with npm and avoid a lot of the
boilerplate shown below.
The download contains two directories, src and min. Both contain the same
files; src contains the JS.Class source code, and min contains a minified
version suitable for production use on the web. Pick which version you want to
use, and copy it into your project. You can then load JS.Class into your pages
as follows.
<script type="text/javascript">JSCLASS_PATH = '/path/to/jsclass/min'</script> <script type="text/javascript" src="/path/to/jsclass/min/loader-browser.js"></script>
On server-side platforms, you load the library like this:
(function() {
var $ = (typeof global === 'object') ? global : this;
$.JSCLASS_PATH = 'path/to/jsclass/src';
})();
if (typeof require === 'function')
require('./' + JSCLASS_PATH + '/loader');
else if (typeof load === 'function')
load(JSCLASS_PATH + '/loader.js');
JSCLASS_PATH tells the loader script where you’re storing the JS.Class
library, and will be interpreted relative to the current working directory.
loader.js is a script that knows how to load packages on any platform,
while loader-browser.js only contains code for loading packages in the
browser, and is thus a little smaller.
This may look like quite a lot of boilerplate, but once you’ve done this you
can use a single mechanism to load JS.Class components (and any other
components you make) on any platform your code needs to run on. That mechanism
is the JS.require() function.
All components that are part of the JS.Class library can be loaded using the
JS.require() function, passing in the name of the object(s) you want to use
and a callback to run once they’re ready.
JS.require('JS.Hash', 'JS.Observable', function() {
// ...
});
The JS.require() function is aware of dependencies and will load everything
you need to use the objects you want. One some platforms, package loading is
asynchronous, and you should be aware of that when structuring your code. If
an object you want to use is already loaded, JS.require() will not reload it.
You’re now ready to start using JS.Class. Dive into the reference documentation linked on the left of this page, and find out how you can use the JS.Class package system to manage dependencies in your own projects.