Objs JavaScript library update

Objs JavaScript library update

I recently completely refactored the Objs library to make a 2.0 version of it. I also moved its source from Google code to Github.

For those discovering the project, Objs is a tiny and non-intrusive library available with an open source GNU GPL v3 license. It is slowly evolving since 2006 to suit my own needs in JavaScript programming. I used it successfully in most of my personal and professional JavaScript projects.

It is also used in the first JavaScript port ever made for PureMVC which was updated recently to follow the new syntax. As it's a non-instrusive library (meaning that it doesn't pollute DOM nor prototype objects) I made a PureMVC EmployeeAdmin demo for Objs+jQuery and another one with Objs+jQuery mobile which will be added to the PureMVC repositories as soon as possible.

The current library is focused on simplicity:

  • It is only 711 Bytes
  • Objs is itself a Function object and the only public method of its API
  • Support namespaces
  • Support inheritance
  • Shortcut to superclass in their subclasses

Simple but powerful. It has been unit-tested and demonstrated to work perfectly on big applications having more than 300 Objs classes.

Project home: Objs on Github
Documentation: Objs wiki on Github


The library syntax was thought to be as near as possible from ExtJS/Mootools/Prototype.

A good sample of the syntax it uses is:

 * Create a constructor for the "HelloWorld" class using the
 * "myclasspath.myapp" namespace.
Objs( "com.example.helloworld.HelloWorld",
	 * Declare a "message" class property.
	 * @type {String}
	message: null,		
	 * Declare an "initialize" method that will automatically be called on
	 * class construct with the same parameters passed to its constructor.
	 * @param {String} message
	 *  Add a message parameter that will be passed from the
	 * "HelloWorld"  constructor to this method on construct.
	initialize: function( message )
		this.message = message;
	 * Declare a public giveMeHello method.
	sayHello: function()

Live "Hello, World!" example on Github.

Source code

The complete and fully documented source code of the library can be read on Github.

But for the fun part, here is the minified (using YUICompressor) 711 chars source code representing the complete source code of the library:

var Objs;new function(){Objs=function(o,u,s){var r,p=typeof u,t,q,n;
if(typeof o!=d){throw Error(j+o)}if(p==d){if(!b[u]){throw Error(g+u)}
u=b[u]}else{if(p=="object"){s=u;u=null}}if(!u&&!s&&b[o]){return b[o]}
delete r[i][m]}if(!r[m]&&r[k][a]){r[k][a].apply(this,arguments)}}};
if(u){u[f]=1;r[k]=new u();delete u[f];r[i]=u;r[l]=u[k]}if(s){n=h.slice(0);
for(t in s){if(s.hasOwnProperty(t)){n.push(t)}}for(q=0;q<n.length;q++)
{t=n[q];r[k][t]=s[t]}}return r};var d="string",l="$super",e="class",i=l+e,
k="prototype",a="initialize",c="$Objs$",m=c+"c",f=c+"e",g="Unexistent super"
+e+": ",j="Invalid "+e+"path: ",b={},h=["toString","valueOf","toLocaleString"]};

Leave a Reply

Your email address will not be published.