Type-js 
Type checking support for javascript
- All types are checked at runtime
- Supported for ES5++ browsers.
- Object roots are freezed after thy are created.
- Initialized objects are prevented from extension.
- To define object you must provide two objects to Type.create(type_definition, prototype);
- _construct function is executed when object is constructed to inherit use _super(arguments) inside of _construct
- _invoke is executed before _construct cross inherited objects on each object construction
- _super() use _super(arguments) call to call inherited method.
- _super is not allowed to be executed inside _invoke call
- In IE 8,7,6 inheritance works but extensions and changes are allowed.
var AdminUser, Group, User;
Group = Type.create({
_group: Type.STRING,
invoked: Type.STRING
}, {
_invoke: function(group) {
this.invoked = group;
},
_construct: function(group) {
this._group = group;
},
setGroup: function(value) {
this._group = value;
},
getGroup: function() {
return this._group;
}
});
AdminUser = Group.inherit({
username: Type.STIRNG,
date: Type.DATE
},{
_construct: function(username) {
this.username = username;
this.date = new Date;
this._super('admin');
},
setUser: function(value) {
this.username = value;
}
});
User = AdminUser.inherit({
username: Type.STIRNG,
date: Type.DATE
},{
_construct: function(username) {
this.username = username;
this.date = new Date;
this._super('test');
this.setGroup('user');
},
setPassword: function(value) {
this.password = value;
}
});
var user = new User('igor');
user.username = 1;
user.date = new RegExp;
user.date = new Date;
user.date = null;
user.date = 1;
user.date = new Date;
User.prototype.one = 1;
User.one = 1;