Javascript supports private and public out of the box. However
inheritance is often claimed impossible or done with prototype.
While inheriting with prototype is not necessarily bad, it
however implies that all inheritable properties have to be public
and all properties should be public in case a function in the
prototype needs to access it.
To make this possible, EnoFJS implements a ClassFactory, handling
all the trouble of scoping and inheriting.
var Dog = clazz(function Dog(name){
this.extend = 'Animal';
this.private = {
name: null
};
this.protected = {
nickName: {
getSet: null
}
};
this.public = {
barkName: function barkName(){
return 'Woof, my name is ' + this.private.name +
', but you can call me ' +
this.protected.nickName + '!';
}
};
});
var dog = new Dog('fluffy duffy');
dog.setNickName('fluffy');
expect(dog.barkName()).
toEqual('Woof, my name is fluffy duffy' +
', but you can call me fluffy!');
LinkedHashMap
A LinkedHashMap has the advantage of a LinkedList, able to quickly
add or remove a Node between already existing nodes. However a LinkedList is slower
in finding an entry in the middle of the list, because it has to search
through the entire list!
With the implementation of a LinkedHashMap, it keeps the ability to insert
or remove nodes like a LinkedList. For searching the implementation of a HashMap
is used. This way you have best of both worlds!
var list = new LinkedHashMap();
list.add(0, 'one');
list.add(1, 'two');
list.add(2, 'three');
expect(list.getById(1).getValue()).toEqual('two');
list.addAfter(1, 'an non integer key', 'four');
expect(list.getById('an non integer key').getNext().
getValue()).toEqual('three');
Serializable
When sending information over the line in json format, the Serializable clazz can help. This Class will help you
in serializing your classes into a json format.
The class also helps you deserialize a serialized object in json format.
var SerializableObject = clazz(function SerializableObject(){
this.extend = 'Serializable';
this.constructor = function constructor(serialized){
this.super(serialized);
};
});
WhereIt
The whereIt is an extention for the Jasmine test framework. Often you have a test cases
where the same process will be executed with different parameters, expecting different
results. The whereIt assists in doing this with a simple configuration!
Configuration will be matched to the variable names!
In modern browsers TypedArrays are introduced. The literal array [] or new Array()
do not support the ArrayBuffer out of the box. To convert an literal array into an
Uint32Array this extention on the Array.prototype is brought to live.
EnoFJS
Inheritance
Javascript supports private and public out of the box. However inheritance is often claimed impossible or done with prototype.
While inheriting with prototype is not necessarily bad, it however implies that all inheritable properties have to be public and all properties should be public in case a function in the prototype needs to access it.
To make this possible, EnoFJS implements a ClassFactory, handling all the trouble of scoping and inheriting.
LinkedHashMap
A LinkedHashMap has the advantage of a LinkedList, able to quickly add or remove a Node between already existing nodes. However a LinkedList is slower in finding an entry in the middle of the list, because it has to search through the entire list!
With the implementation of a LinkedHashMap, it keeps the ability to insert or remove nodes like a LinkedList. For searching the implementation of a HashMap is used. This way you have best of both worlds!
Serializable
When sending information over the line in
json
format, theSerializable
clazz can help. This Class will help you in serializing your classes into ajson
format.The class also helps you deserialize a serialized object in
json
format.WhereIt
The
whereIt
is an extention for the Jasmine test framework. Often you have a test cases where the same process will be executed with different parameters, expecting different results. ThewhereIt
assists in doing this with a simple configuration!Configuration will be matched to the variable names!
ArrayConverters
In modern browsers
TypedArrays
are introduced. The literal array[]
ornew Array()
do not support theArrayBuffer
out of the box. To convert an literal array into anUint32Array
this extention on theArray.prototype
is brought to live.Usage: