Contents

# URI http://metadea.de/V/

Draft Release 2012-05-24 Uli Riehm. Please feel free to .

Downloads

Download V.js (source) v0.2
Download V.min.js (minified) v0.2
See also source of this html document
Watch your IE9, Firefox or Chrome console live
Run sample 'MyProject.MyClass' class function on jsFiddle.net
Run 'the quick read': abstract My.Vehicle and My.Car class functions on jsFiddle.net

classical inheritance: the javaScript class function

# I have seen javaScript first time in 1996 in a Netscape Navigator. In 1999, Douglas Crockford let us know, it's the wrrld's most misunderstood language. He's right, he will ever be right.

But we were creating some classical procedures, named functions and we wrote events into html attributes.
In fact, JavaScript was boring return falses, dangerous namings, bogus undefineds and the annoying alert.

Ten years later, in 2008 the world has changed. John Resig has born jQuery.
jQuery learned us how a javaScript function is really to be used.
To write functions returning a closure for a function. That you do more likely use a variable to a function, instead of using the function-name. You can call and apply the function variable, without loosing the ability to use the variable() by statement.

The jQuery Function also upgrades the window, the DOM for HTML/CSS, XML and basically any object,
in chaining by selector arguments into a new $ instanceof jQuery Object.

The object of function jQuery allows us to easily select html elements by id, by css names, and call fn functions on the selected DOM objects.

If you don't know jQuery please visit jQuery.com and run interactive scripting on jsFiddle.net.
If you're interested in javaScript please also read wrrlds most misunderstood language, and for javaScript basics Code Conventions for the JavaScript Programming Language on crockford.com.
The most comprehensive, readable and reliable references today, about javaScript and the DOM for HTML and CSS you will find on Mozilla's Developer Network.
Also useful for browser quirks are caniuse.com and quirksmode.org.
Do not use w3schools, read why on w3fools.com!

Now in 2012, years of camping on crockford.com, ejohn.org and developer.mozilla.org websites, the most confusing but interesting part until today in javaScript is, to understand Function's function, prototype and prototype's constructor.

This is also about the new operator to create what every javaScript object is:
An object (instance)of A function, at least also instanceof Object function.

V.construct and your javaScript class function

# javaScript is all about function closures, and their 'new' objects, instances of the function.

Basically "how it works - a javaScript class function" is done by some sugar in V.construct function:
But you have to write your class function.

All functions, in syntax designed to be constructor functions, are called 'class function's.
Using 'new' operator, object instances will be created, that are called 'class object's.

You have to write your function, so that it is a constructor function.

The only magic is javaScript code { Chuck, it's messy; }!

To be A class function,

  • A function is prototypable without executing,
    returning a new uninitialized A object for derived class function prototypes.

  • A function is a constructing function, by
    returning a new A(), or undefined, or by throwing an exception.

  • A function is applying the base class constructor function to this.

The V.Class function is the current template for an 'ultimate' derivable base class function – having initialization and bubbeling OnInitialized and Dispose builtin.

We create the MyProject.MyClass class function;
MyProject.MyClass will be constructed and then 'derives from' V.Class class function:

Simply copy & paste the template and change the variable names to your class function's name, this is licenced under terms of MIT licence.

In fact, to learn javaScript class functions, it is recommendable to write code once manually, but to be productive, do create new classes by copying and changing the template.

Also run and change MyProject.MyClass interactive on jsFiddle.net,
and see 'the quick read' for a minimum of a javaScript class function.

/// <reference path="V.js" /> // use intellisense

window.MyProject = window.MyProject || { }; // Your namespace

// Your class function
V.Class.construct( MyProject.MyClass = function MyProject_MyClass(config) {
  if (config instanceof V.Construction) return; // prototyping
  if (!(this instanceof MyProject.MyClass)) { // functioning
    return new MyProject.MyClass(config);
  } // constructing

  // call base constructor
  V.Class.call(this, config);
  
  // private variables
  var that = this;
  var name = config.name;
  
  // delete references (user arguments)
  delete config;

  // private function
  var initialize = function () { };
  
  // public overridable function
  this.Hello = function (yourname) {
    return (name ? name + ': ' : '') + 'Hello ' + (yourname || 'World') + '!';
  };
  
  // public override function
  var base_OnInitialized = this.override(this.OnInitialized, function() {

    // call base OnInitialized
    base_OnInitialized.call(this);
  });
  
  // public override Dispose
  var base_Dispose = this.override('Dispose', function() {

    // In Dispose, do cleanup resources
    delete name;

    // call base Dispose:
    base_Dispose.call(this);
  });

  // call initialize // call OnInitialized if this object isn't more derived
  initialize.call(this); if (this.constructor === MyProject.MyClass) this.OnInitialized();
}, 'MyProject.MyClass');

What happens?

Your function is defined into the namespace variable MyProject, globally named 'MyProject.MyClass'.
Then V.construct is called using three arguments:
baseType function V.Class,
protoType function MyProject.MyClass,
and the globalName string 'MyProject.MyClass'.

V.construct validates your function to be accessible, 'evaluable' in global and
prepares, 'constructs' your function protoType, to be derived from baseType.

V.Class.construct( MyProject.MyClass = function MyProject_MyClass(config) {
}, 'MyProject.MyClass');

How do I create A class function?

In first line of your class function, you are required to do 'prototyping', what also makes the first argument required. It allows V.construct to create a new object using the one signaling argument, for use as uninitialized prototype object of a derived class function.

  if (config instanceof V.Construction) return; // prototyping

Your class function is also required to be a constructor function, so that it is not 'functioning', call'd or apply'd when this isn't an instanceof your function.
Always return a new or an existing object instanceof your class function, or undefined:

  if (!(this instanceof MyProject.MyClass)) { // functioning
    return new MyProject.MyClass(config);
  } // constructing

Now your function is 'constructing', 'this' is your class object instance.
Note also, that the declared first argument used in V.construct is now your first argument. It is whatever you want to be the first argument (only except of an object instanceof V.Construction), it even may be undefined!

Your class function is required to re-call your base constructor:

  // call base constructor
  V.Class.call(this, config);

All base class functions are initialized now.
Declare here your functions and objects variables, privates (var) and publics (this, that).

You will be required to have the 'that' variable, in private functions, where this is window.
You also can use 'that' in public functions to triple equals true: this === that so your function isn't called in another context. That (and this) now makes your javaScript class function more reliable and secure!

  var that = this;
  var name = config.name;
  
  // private function
  var initialize = function () { };
  
  // public overridable function
  this.Hello = function (yourname) {
    return (name ? name + ': ' : '') + 'Hello ' + (yourname || 'World') + '!';
  };
  
  // public override function
  var base_OnInitialized = this.override(this.OnInitialized, function() {

    // call base OnInitialized
    base_OnInitialized.call(this);
  });

  // public override Dispose
  var base_Dispose = this.override('Dispose', function() {

    // In Dispose, do cleanup resources
    delete name;

    // call base Dispose:
    base_Dispose.call(this);
  });

Using a public Dispose function, you can surely cleanup resources. Do remove attached event handlers, delete private vars and this public member variables.
Because there is no destructor for javaScript objects, you may yourself somewhere call Dispose, to cleanup your resources in-instance, before you delete that var.

As last action in your class function do initialize your class

  // call initialize // call OnInitialized if this object isn't more derived
  initialize.call(this); if (this.constructor === MyProject.MyClass) this.OnInitialized();

You may not be required to have a private initialize function, but you should ensure, that your base OnInitialized function will be called (surely only if there is one).

The initialize is useful, to be executed when all your private and public variables have been defined (the initialize function is declared and defined as first, but executing as last on constructing this).

Usage of your class object, the MyProject.MyClass object:

// Example Usage (currently running in console)

window.programming = new MyProject.MyClass({ name: 'ECMAScript' });

var sayHello = function () {
  if (programming && console) {
    console.log(programming.Hello());
  }
};
if (programming && console) console.log(programming.Hello('YOU'));

$(function () {
  sayHello();

  var helloEvent = function (e) {
    e.preventDefault();
    sayHello();
  };

  $('#hello_ecmascript').wrap(
    $("<a href='#hello_ecmascript'/>").click(helloEvent)
  );
  $('.hello_ecmascript').each(function () {
    $(this).wrap($("<a />").click(helloEvent));
  });
});

// Open your IE9, Firefox or Chrome console and watch
ECMAScript: Hello World!

// Try
console.log(programming.Hello('YOU'));

Run MyProject.MyClass interactive on jsFiddle.net

the quick read

# Using V.construct
for a base class function in declarative syntax, and
for a derived class function in functional syntax:

/// <reference path="V.js" /> // use intellisense
window.My = window.My || {}; // Your namespace


// Your abstract base class function // in declarative syntax

My.Vehicle = function My_Vehicle(config) {
  if (config instanceof V.Construction) return; // prototyping
  if (!config) throw new V.Ex.ArgumentNot(My.Vehicle, 'config');
  if (!config.manufacturer) {
    throw new V.Ex.ArgumentNot(My.Vehicle, 'config.manufacturer');
  }
  if (!(this instanceof My.Vehicle)) { // functioning
    throw new V.Ex.AbstractNoFunction('My.Vehicle');
  } // constructing
  if (this.constructor === My.Vehicle) {
    throw new V.Ex.AbstractNotNew('My.Vehicle');
  }

  var that = this;
  this.Manufacturer = config.manufacturer || 'Manufacturer';
  this.Color = config.color;

  // delete some references (arguments)
  delete config;

  /* private function *
  var initialize = function My_Car__initialize() { }; //*/

  /* public overridable function */
  this.SetColor = function My_Vehicle_SetColor(color) {
    // if (this !== that) throw new V.Ex.InvalidThisInstance('My_Car_SetColor', this, that);
    this.Color = color;
    return this;
  }; //*/

  // call initialize // call OnInitialized if this object isn't more derived
  //initialize.call(this); // abstract not (this.constructor === My.Vehicle) this.OnInitialized();
}; // My.Vehicle

// For your base class function,
// use V.construct
// using undefined (optional) or also an object {} as prototype:

V.construct(My.Vehicle, 'My.Vehicle');
// V.construct(undefined, My.Vehicle, 'My.Vehicle');
// V.construct Usage: (baseType, protoType, globalName);


// Your derived class function // in functional syntax (nicer)
// use implicit V.construct function

My.Vehicle.construct(
My.Car = function My_Car(config) {
  if (config instanceof V.Construction) return; // prototyping
  if (!config) throw new V.Ex.ArgumentNot(My.Car, 'config');
  if (!(this instanceof My.Car)) { // functioning
    return new My.Car(config);
  } // constructing

  config.color = config.color || 'silver metallic';

  // call base constructor
  My.Vehicle.call(this, config);
  // call base constructor alternative
  // this.constructor.construction.baseType.apply(this, config);

  var that = this;

  // delete some references (arguments)
  delete config;

  /* private function *
  var initialize = function My_Car__initialize() { }; //*/

  /* public overridable function *
  this.Hello = function () {
    // if (this !== that) throw new V.Ex.InvalidThisInstance('My_Car_Hello', this, that);
    return this;
  }; //*/
  
  /* public override function *
  var base_SetColor = this.override('SetColor', function My_Car_SetColor(color) {
    return base_SetColor.call(this, color);
  }; //*/

  // call initialize // call OnInitialized if this object isn't more derived
  //initialize.call(this); if (this.constructor === My.Car) this.OnInitialized();
}, 'My.Car');

// leave inline comments for better reading!


// Example Usage (currently running)

// try and catch a rock solid V.Ex
try {
  var myvehicle = new My.Car({ manufacturer: undefined });
}
catch (ex) {
  if (ex instanceof V.Ex.ArgumentNot) {
    // don't kill closures
    if (console) console.warn(ex.toString());
  }
  else {
    throw ex; // do kill closures if not catched
  }
}
delete myvehicle; // cleanup something

// Use the class as object in a public variable
window.myVehicle = new My.Car({ manufacturer: 'Mercedes-Benz' });
//myvehicle.SetColor('black metallic');

if (myVehicle && console) {
  console.log('myVehicle instanceof My.Car === ' + (myVehicle instanceof My.Car));
  console.log('myVehicle instanceof My.Vehicle === ' + (myVehicle instanceof My.Vehicle));
  console.log('myVehicle instanceof Object === ' + (myVehicle instanceof Object));
}

var carPrinter = function (e) {
  if (e && e.preventDefault) e.preventDefault();
  if (myVehicle && console) {
    console.log(myVehicle.Manufacturer);
    if (myVehicle.Color) console.log(myVehicle.Color);
  }
};

$(function () {
  carPrinter();
  $('#hello_My_Car').wrap(
    $("<a href='#hello_My_Car' />").click(carPrinter)
  );
  $('.hello_My_Car').each(function () {
    $(this).wrap(
      $("<a />").click(carPrinter)
    );
  });
});

// Open your IE9, Firefox or Chrome console and watch

// our rock solid V.Ex.ArgumentNot object, catched as warning in consoles:
//" V.Ex.ArgumentNot: My.Vehicle: config.manufacturer is == 0/false/null/undefined "

// our instance object and public member variables
myVehicle instanceof My.Car           // true
myVehicle instanceof My.Vehicle       // true
myVehicle instanceof Object           // true
myVehicle.Manufacturer                // Mercedes-Benz
myVehicle.Color                       // silver metallic

// Try!
myVehicle.Manufacturer = 'EU Ford Fiesta';
myVehicle.SetColor('blue metallic');

See also source of this html document
Run 'the quick read' interactive on jsFiddle.net

how it works - a javaScript class function

# It is classic. In javaScript:

  • Many class functions (constructing function),
    each of only one prototype class object (prototyping base function).
  • All new objects will become at least instanceof Object:
    Your class object becomes instanceof your class function and Object,
    like in var theCar = new My.Car(); now theCar is instanceof My.Car, My.Vehicle and Object.

In instance of your class function (constructing this),

  • you apply the base function (this)
  • you can be private (class closure)
  • you can be public and override (this)

The class function should be defined in a global namespace variable.

These lines of javaScript sugar in V.construct function do the magic 'prototyping':

// create a construction info
protoType.construction = new V.Construction({
  globalName: globalName,
  protoType: protoType,
  baseType: baseType
});

// create an uninitialized, 'prototyped' object (instance)of the base class function
protoType.prototype = new baseType(protoType.construction);

// reset the constructor
protoType.prototype.constructor = protoType;

The V.construct function is validating arguments and also attaches itself to your new class function, so you can derive your class function using

My.Vehicle.construct( My.Car = function (config) { /**/ }, 'My.Car');

instanceof your class function, and V.Construction

# See now the advantages of the instanceof operator,
and the difference to the typeof operator, what is rarely discussed in the wrrld:

The typeof operator is (today) telling you if the variable is undefined, boolean, string, number, object or function. The typeof is about the simple-type of an instance.

The instanceof operater is telling you of what function(s) the variable has been constructed, so about derived function-types in an object's instance:

The anonymous object {} is instanceof Object.

var o = {};
o instanceof Function           // false
o instanceof Object             // true
typeof o === 'object'           // true

javaScript's most misunderstood object may be (Function function)'s object: each function statement creates a new object instanceof Function.

var f = function () { };
f instanceof Function           // true
f instanceof Object             // true
typeof f === 'function'         // true // typeof says not 'object'

Now if you declare a variable with a new object of your function:

var m = new MyProject.MyClass();

The variable m will be instanceof My.Car, My.Vehicle and Object:

m instanceof My.Car             // true
m instanceof My.Vehicle         // true
m instanceof Function           // false // it is not an object of Function !
m instanceof Object             // true
typeof m === 'object'           // true

The javaScript syntax for a 'class function' uses the instanceof operator two times, for prototyping and for functioning.

The first argument in a class function is required, to do 'prototyping': The class returns immediately, if the first argument is instanceof V.Construction. V.construct only needs a 'new' object of the base class function, not the result object, what the base class function would provide and is designed to be.

  if (config instanceof V.Construction) return; // prototyping

The V.Construction object in config argument variable is also used as 'class info'. It is assigned public to the class function object (in MyProject.MyClass.construction respectively this.constructor.construction).

The class is required to be a constructor function, if this isn't instanceof the class function. Return a new object of your class function. Return undefined, to not create a new one. Throw an exception, if your class does not have an argument-less constructor.

  if (!(this instanceof My.Car)) { // functioning
    return new My.Car(config);
  } // constructing

You can also make your class function having no 'functioning' (like V.Class):

  if (!(this instanceof My.Vehicle)) { // functioning
    throw new V.Ex.AbstractNoFunction('My.Vehicle');
  } // constructing

An abstract class function (like V.Class) does also

  if (this.constructor === My.Vehicle)
    throw new V.Ex.AbstractNotNew('My.Vehicle');

Your rock solid class function is returned when it's not called 'new', by returning itself new, by returning undefined, or by throwing an exception.

If your class function is not returned until now, you are now really 'constructing' your class object.

Do call or apply your base class function:

My.Vehicle.call(this, config);

Declare private and public object variables.

First declare your private initialize and other private functions,
then declare and override also your public overridable functions.

The override function is a prototype shared function, attached by V.construct to your class function.
To override a base public function or a shared function do

  var base_SetColor = this.override('SetColor', function My_Car_SetColor (color) {

    // do something before base_SetColor

    color = base_SetColor.call(this, color);

    // do something after base_SetColor

  };

As last action in your class constructor function, call initialize, and also ensure to call this.OnInitialized, if this.constructor is your class function (most derived).

  // call initialize // call OnInitialized if this object isn't more derived
  initialize.call(this); if (this.constructor === My.Car) this.OnInitialized();

The initialize function is declared and defined as first, but executing at least on constructing this.
The private initialize function allows you to run what your class actively does,
but is defined in most early lines of your class function code, making your class function easier to read.

Initialize is useful, to be executed when all your (in class closure) declared private and public variables have been defined, so you can reference (var) objects and attach event handlers.

Other ways of prototyping in javaScript are hard to get. There are some ways of using prototype and constructor. I don't want to confuse: the V.construct and your own class function is the only way

  • your global class function is the constructor
  • you can use private variables, hiding variables inside your class object instance
  • you can override publics in instance, without over-writing the base class public functions
  • you call your base function using your arguments, or not
  • you are in-object, of-instance, not only using shared prototype functions

See 'the quick read'!
See also source of this html document
Run 'the quick read' interactive on jsFiddle.net

javaScript functions and the function-name

# There are four different 'access levels' for variable-names:

  • anonymous

    function () { }
  • private (originally in var or named)

    var fn = function named() { }
  • public global (originally global)

    window.My = window.My || {}
    My.Prop = {}
  • public instance (originally this)

    MyProject.MyClass = function(config) { // ...
      this.Name = config.name;
    /*...*/ }
  • public shared (originally in prototype; defined in instance, if not declared on instance)

    MyProject.MyClass.prototype.Action = function () {
      // this way you have a instance public shared function
      // on your object in this.
    
      // Feels like static 'this' functions in C#:
    
      // A shared prototype function becomes automatically
      // A public instance function and is overridable.
    
      // var vehicle = new Car();
      // If function A is defined on instance (vehicle.A, this.A),
      // the instance function is returned (vehicle.A, this.A),
      // not the shared by prototype (vehicle.constructor.prototype.A, Car.prototype.A)!
    }

These statements are clearly private or public:

a private function

var fn = function () { };

a Public function

this.MyFn = function () { };

However to have some nicer debug output, you may define a function-name for your function:

var fn = function MyProject_MyClass__fn() { };
this.MyFn = function MyProject_MyClass_MyFn() { };

It is helpful for the debugger, being clear about what function is crashing into debug.
Using V.getName and V.evalName you can get a names out of objects and functions:

V.getName(fn, undefined, 1, true); // returns 'MyProject_MyClass__fn' instead of 'function'

To name a function, you need a long function-name: it is only a string, it is therefore parsable from Function's toString(), but you are required to have a globally unique function-name.

For example: it is a closure (initialize), in a closure (V.Class), in a closure (anonymous, global).

The rule for a function-name is, to use parent's variable-names to build a function-name:

V.Class = function V_Class(config) {                      // V.Class declaration
  //...
  var initialize = function V_Class__initialize () { };   // private in class
  //...
};

Public variable-names like namespaces, functions and objects are upper cased, separated using one underscore, whereas private variables are lower/camel cased and separated in two underscores.

But: Never use function statement in your code. If you do, you likely get once the semicolon syntax error.
See also JavaScript as a First Language (John Resig) on ejohn.org.

function do_never() { }     // function statement without semicolon

var use = function () { };  // assignment statement new Function
                            // to var statement or global variable

                            // requires you to need a semicolon
                            // making you never happen undefined and semicolon syntax errors
                            // using notepad++ (syntax highlighting edit)
                            // or IDE (syntax refactoring edit)

use.call(this, arg0);       // call by call'ing the Function object
use.apply(this, [ arg0 ]);  // call by apply'ing the Function object
use(arg0);                  // or call by variable-name (without this)

return use;                 // do return or assign = the Function object

// only conditional, loop and try statements will have no semicolon, except of function:
if { } else { }
switch { }
for { }
while { }
try { } catch (ex) { throw ex; }

V.Ex exception class function

# The first most basic class function that I want to introduce is V.Ex.

Simply use it doing

throw new V.Ex('Do not something wrong...');

javaScript throws an exception. javaScript will kill any running closure, where the exception was thrown!
The advantage of throw is, that a debugger like IE9, Firefox or Chrome halts exactly there.

If you're really clear with your code, you can make it using V.Ex really rock solid javaScript.
You may throw if an argument was not, 0, false, null or undefined:

if (!color) throw new V.Ex.ArgumentNot('My_Car_SetColor', 'color');
// console outputs
//" V.Ex.ArgumentNot: My_Car_SetColor: color is == 0/false/null/undefined "

throw new V.Ex.ArgumentInvalid('My_Car_SetColor', 'color', 'CSS valid value string only!');
// console outputs
//" V.Ex.ArgumentInvalid: My_Car_SetColor: color: CSS valid value string only "

You can now yourself try and catch a thrown exception: Because of V.construct and derived V.Ex class function objects, you can make a difference in exceptions using instanceof:

try {
  mycar.SetColor('black');
}
catch (ex) {
  if (ex instanceof V.Ex.ArgumentInvalid) {
    // todo: Show a validation error
    console.warn(ex.toString());
    return;
  }
  else {
    throw ex; // re-throw uncatched exceptions
  }
}

However, also without depending on typed exceptions, the V.Ex classes output a clear message.

V.Ex builds a string of it's arguments, by appending strings and trying to lookup the names of objects and functions.

specialized V.Ex class functions

# class function of V.Ex Description
V.Ex.ArgumentNot (fn, arg)
'fn': 'arg' is == 0/false/null/undefined
V.Ex.ArgumentNotInstanceof (fn, arg, instanceName)
'fn': 'arg' is not instanceof 'instanceName'
V.Ex.ArgumentInvalid (fn, arg)
'fn': 'arg' is invalid
V.Ex.AbstractNoFunction (fn)
'fn': is abstract and has no function
V.Ex.AbstractNotNew (fn)
'fn': is abstract and cannot be new
V.Ex.InvalidThisInstance (fn, instance, that)
'fn': 'instance': this is invalid instance, not that: 'that'

using function-typed javaScript

This heading is pre-released and subject to change. Please feel free to contact me.

# There are some cool things you can do with new objects, and class functions in javaScript!

An interesting thing demonstrating the power of class objects may be V.instance. You can attach one or more objects grouped by function-type to another object, like an element in your HTMLElement:

var element = document.getElementById('myid');
var myobject = new MyProject.MyClass(element);
// Now attach your object to the element (MyClass may do this itself in initialize)
// This does attach it to the level of V.Class.
V.Instance(element, V.Class).Set(myobject);
// Now get your object, checked to be minimum instanceof MyProject.MyClass
var myobjectagain = V.Instance(element, V.Class).Get(MyProject.MyClass);
// myobject === myobjectagain

This allows your class function not only to be a constructor function simply returning a new object. You can also return an existing object, or undefined, so that myobjectagain would be undefined now, because there wasn't created one before:

if (!(this instanceof My.Car)) { // functioning
  return V.Instance(element, My.Vehicle).Get(My.Car); // may be undefined
} // constructing

The next interesting thing is using V.Factory. A factory info is simply a jQuery selector, combined with your class function:

// do this after V.construct'ing your My.Car class function:
V.Factory('My.Car').Register({
  selector: '.MyCar .MyVehicle',
  func: My.Car
});

Now, in your My.Vehicle class instead of throwing 'abstract', you can do

// ...constructing
if (this.constructor === My.Vehicle) {
  // only if this should be an object of My.Vehicle (not derived)
  return V.Factory(My.Vehicle).Create(config.element, config, this);
}

Calling an abstract class function new would throw an exception. However using V.Factory you can make your abstract class function functioning, by returning the most derived class function's object:

var myVehicle = My.Vehicle(element);
// My.Vehicle doesn't throw 'abstract and no function' anymore,
// instead it returns now undefined or
// myVehicle instanceof My.Car // true

The whole syntax of a class function, the way V.construct does and how cool javaScript is about objects, is a totally new experience of the wrrld's most misunderstood programming language.

This is a new way of designing a function, of creating and using objects. It is an additional way of writing javaScript, to get your code into namespaces, to group your code into entities, being able to hide data into your object's class function closures, making your code base rock solid.

Again: Read John Resig's blog and books about javaScript.
Read coding conventions for javaScript, that Douglas Crockford has told us.
Remember: It's javaScript. V doesn't change anything. () { In fact, it was Chuck.Norris class function; }

Draft Release: 2012-05-24 Uli Riehm. Please feel free to .