Small javascript framework

VNLS is small javascript framework. It's purpose is to provide boundaries to the very flexible Javascript language and provides a way to write code in a consistent and uniform manner that can be used on the server, Nodejs AND in the browser.

And don't we all like to 'Write once and use many'? Consider this framework as an experiment in multi-platform coding.

  • A simple mechanism for dealing with name-spaces.
  • A better typeof.
  • A clear separation between Javascript objects (the classical OOP approach with inheritance) and singleton patterns.
  • An event model (reverse engineered from nodejs's eventemitter) for use in other environments
  • Promisses/Futures.
  • It does not, extend the javascript core language or any other object, except for some ES5 methods

On node nodejs npm install VNLS

Then, somewhere at the top of your code


There is no need to bind it to a var because var VNLS is made global to the nodejs process so it's behavior is exactly like in a browser environment. All-though this IS a kind of pollution on nodejs.

In a browser (you may also download the file first):

 <script type="text/javascript" src=""></script>

A class is an object definition but never used directly. We are going to write a class in the 'test' namespace. The __init__ method is called upon creation.

            function MyClass() {
            MyClass.prototype.__init__ = function(str){
                 this.text = str;
            MyClass.prototype.getText = function(){
                return this.text
            return MyClass;

We 'r going to use the previous class twice: the method getObject must have least 2 arguments.

  1. the namespace
  2. the class_name
  3. optional arguments (passed to the __init__ method)

To create an object:

  var my_class_1 = VNLS.getObject('test',"MyClass","foo");
  var my_class_2 = VNLS.getObject('test',"MyClass","bar");


I wrote a Promise as an example This object is extended with a EventEmitter.

A namespace is used to extend the global VNLS object. All it's methods are therefor singletons.

   myMethod : function(){
     return 'test';



In normal use there are no dependencies, it will run in the browser and on nodejs out of the box.

When contributing, experimenting or if you want to build your own, use the following node_modules.

  • docco Documentation npm install docco
  • jasmine-node Testing npm install jasmine-node
  • nodewatch Autotesting TDD npm install nodewatch
  • uglify-js Building npm install uglify-js
  • jake rake, make, ant substitute (Java-script all the way) npm install -g jake

For jake these are the commands:

  • jake build : build 2 versions (1 minified) in './lib/*'
  • jake test : run the specs
  • jake autotest : run the specs on a filechange for TDD
  • jake docs : generate documentation in ./docs

For testing in a browser environment just point your browser to 'specs/index.html'. It should run the same specs as jake test does. (The tests cover both browser and server)

  • Write some examples and howtos in the wiki
  • Clean up the specs
  • Refactor some bits following Felix's coding guidelines.