|
GettingStarted
See how objx can make your JavaScript simpler
Featured Getting StartedWhat is objx?objx puts JavaScript on steroids. It wraps normal JavaScript objects and enhances them via a suite of plugins. For example: var normalArray = [1, 2, 3]; var enhancedArray = objx(normalArray); The enhancedArray object can now have a wide range of actions run against it, depending on which plugins you include. How do I use it?To use Objx, you just need to: 1. Include the Objx core libraryAdd the following code to the <head> of your web page: <script type="text/javascript" src="http://objx.googlecode.com/svn/trunk/src/objx.js"></script> 2. Include any plugins you plan on usingIn the same way you included the objx core library, you need to include any plugins you plan to use. For example: <script type="text/javascript" src="http://objx.googlecode.com/svn/trunk/plugins/src/collections/group.js"></script> <script type="text/javascript" src="http://objx.googlecode.com/svn/trunk/plugins/src/oo/class.js"></script> (Check the plugin directory for more) 3. Start enhancing your JavaScriptYou can now write code that uses Objx. Quick tutorialSetting up your first pageobjx runs in the browser so all you need to start writing objx code is:
Create test.htm pageCreate a new text file called test.htm and copy and paste the following page template: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml2.dtd">
<html xmlns="http://www.w3.org/2002/06/xhtml2/" xml:lang="en">
<head>
<title>My first objx page</title>
</head>
<body>
</body>
</html>Add the objx core fileWe need to include the core objx file in the page by adding the following script tag to the head of the page: <script type="text/javascript" src="http://objx.googlecode.com/svn/trunk/src/objx.js"></script>
Using the built-in each pluginTo iterate over an array in JavaScript we have to do something like this: var a = [1,2,3];
for (var i = 0; i < a.length; i++) {
alert(a[i]);
}Objx makes this much easier. Create a <script> tag in the head of your page and write the following code: var a = [1,2,3];
objx(a).each(function(item){
alert(item);
});When you visit the page (in your web browser), you'll get three alert boxes containing the items in the array. Adding pluginsBrowse the plugins to see what capabilities are available. To include the plugin in your page, just add another <script> tag pointing to that file after the objx.js include. | |