Magic javaScript object in detail

Overview

Configuration metadata contains a lot of configuration information, including constructor arguments, property values, and container-specific information such as initialization method, static factory method name, and so on.

Configuration Style

In Bearcat, configuration metadatas are recommended to write Magic, self-described javaScript objects. Howerver, for some history reason, it can be written in JSON-style configuration file like context.json for example, or it can be written in the code file with simple javaScript objects. The only difference between these two styles is that code-based meta’s func attribute must be Function specified by the constructor function of the bean, and the configuration-file-based meta’s func attribute is a String to specify the relative location of node.js file path that contains the constructor function.

magic javaScript objects
car.js

1
2
3
4
5
6
7
8
9
10
var Car = function() {
this.$id = "car"; // id car
}
Car.prototype.run = function() {
console.log('run car...');
return 'car';
}
module.exports = Car;

code-based meta
car.js

1
2
3
4
5
6
7
8
9
10
11
12
var Car = function() {}
Car.prototype.run = function() {
console.log('run car...');
return 'car';
}
// func is the constructor function
module.exports = {
id: "car",
func: Car
};

configuration-file-based meta
car.js

1
2
3
4
5
6
7
8
var Car = function() {}
Car.prototype.run = function() {
console.log('run car...');
return 'car';
}
module.exports = Car;

context.json

1
2
3
4
5
6
7
{
"name": "simple",
"beans": [{
"id": "car",
"func": "car"
}]
}

Configuration attribute

Bean attribute

Bean attribute will be wrapped into a BeanDefinition object.

Special attribute