Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
rdking edited this page Dec 5, 2014 · 2 revisions

#Class.js Library API and Tutorials

##API The Class.js Library is currently comprised of 4 files:

##Tutorials Sorry, no tutorials yet.

##Why Class.js? I've been using JavaScript since it first appeared in browsers. Like most programmers back then, I thought of it as a toy scripting tool just to make html pages do semi-interesting things, if not slowly. But over the years, JavaScript has grown from being just a toy language to something powerful enough to handle many different kinds of uses on more platforms than anyone originally suspected. Node.js, jQuery, Prototype, TypeScript, CoffeeScript, and so many others have come along and added even more fuel to the use case fire for JavaScript. Now it's not even uncommon for entire applications to be written using JavaScript. But there-in lies the rub.

JavaScript is a prototype-based language. When it comes down to it, there are really only 3 unique things in JavaScript: primitives, objects and closures. Saying this might seem strange since I didn't mention functions, and variables. This may seem even more strange given that much of JavaScript development is functional instead of object-oriented. However, consider the following:

  • all variables in JavaScript are either primitives or objects.
  • all closures in JavaScript are functions.
  • all functions in JavaScript are objects.

From this, it stands that excepting the control logic, all things in JavaScript are either primitives, objects, or closures. So even though JavaScript isn't object oriented, it is most certainly an object language.

Given the last 2 statements, it's pretty clear that all closures are objects. The only difference between a JavaScript object and a JavaScript closure is that closures add a so-called privileged area to an object. Closures, like the inside of a closed box, can't be seen by anything except the box itself. Only items created inside the closure have access to the things inside the closure. Many JavaScript libraries have taken advantage of this fact. Some are even class factories with basic private and public scopes. So again? Why Class.js?

Simply put, I wanted it and no one else had done it yet. Sure, there's things like Prototype, but I'm not really a fan of the notation, and I can't create a protected scope very easily. There's also things like CoffeeScript and TypeScript, but I don't want to have to compile a scripting language just to use it, or use non-JavaScript syntax in my JavaScript code. Hopefully, this is a good enough explanation for why I did what I did, as well as for what you can initially expect from this library.

Clone this wiki locally