@jf/object 
Class providing dot path syntax for properties, JSON serialization, singletons and more.
Usage

Objects as parameters
You can pass several objects and will be merged recursively.
const obj = new jfObject(
{
a : {
b : 0
c : 2
}
},
{
a : {
b : 1,
}
},
{
a : {
c : 3
}
}
);
console.log(obj.toJSON());
Dot notation
You can use dot notation in order to assign/retrieve/test nested objects.
const obj = new jfObject();
obj.set('d.e.f', 5);
console.log(obj.toJSON());
console.log(obj.get('d.e'));
console.log(obj.has('d.e.f'));
Merging objects
Objects can be merged in 2 ways:
- Recursively: Use
obj.merge(...).
- Overwrite existing keys: Use
Object.assign(obj, ...)
const obj = new jfObject(
{
a : {
b : 0
}
}
);
obj.merge(
{
a : {
c : 1
}
}
);
console.log(obj.toJSON());
Object.assign(
obj,
{
a : {
c : 2
}
}
);
console.log(obj.toJSON());
Iterating over properties
You can use new ES6 loop for..of:
const obj = new jfObject(
{
a : 1,
c : 2,
f : 3,
h : 4
}
);
for (const prop of obj)
{
console.log('%s = %s', prop, obj[prop]);
}
Keys & values
If you need to split object into keys and values, you can use split or toArray methods.
const obj = new jfObject(
{
a : 1,
c : 2,
f : 3,
h : 4
}
);
console.log(obj.split());
console.log(obj.toArray());
Singleton
If you need to share the same instance between differents external modules,
you can use static method i() in order to retrieve the same instance
anywhere in the app.
class User extends jfObject
{
}
function onAjaxResponse(data)
{
User.i().setProperties(data);
}
<user-info data="{{User.i()}}" />