Zeanium
简体中文文档
Introduction
Zeanium is fully oop javascript framework, you can define Class object、module and soon. It support front-end and back-end in the same api what we provide.
Builtin api list
-
zn.idle()
: empty function
-
zn.idleArray()
: return empty array
-
zn.idleObject()
: return empty object;
-
zn.format(string, argv...)
: string is input value, argv is any string arguments. Such as:
1. zn.format('hello {0}, you are {1} year.', 'yangyxu', '2017');
2. zn.format('hello {0}, you are {1} year.', ['yangyxu', '2017']);
The code 1 is the same with code 2. The output is "hello yangyxu, you are 2017 year."
-
zn.uuid()
: return uuid string value
-
zn.serializeJSON(jsonObject)
: serialize json data
-
zn.fix(target, argv...)
: if target has no key in arguments key, the function will extend object arguments value to target
-
zn.extend(target, argv...)
: the function will extend object arguments value to target
-
zn.overwrite(target, argv...)
: get argv value to overwrite the target value
-
zn.path(target, path, value)
: set or get the value for the path in target
-
zn.invoke(target, path, args)
: args as arguments, invoke the target path function
-
zn.deepEachObject(data, handler, context)
: deep each object, data the input value, handler is each function, context is the scope for each function, the output is object value;
-
zn.arrayValueToObject(data, handler, context)
: the function is the same with zn.deepEachObject, but the data type of input is array;
-
zn.toString(value)
: get string value;
-
zn.each(target, callback, context)
: each target, callback is the each function, context is scope for each function
-
zn.clone(target)
: clone target to a copy
-
zn.type(target)
: get type for target
-
zn.is(target, type)
: judge target type is or not type
-
zn.may(target, name)
: judge target has "name" event
-
zn.can(target, name)
: judge target can exec "name" event
-
zn.has(target, name)
: judge target has "name" property
-
zn.get(target, name)
: get "name" value from target object
-
zn.set(target, name, value)
: set value to target name property
-
zn.gets(target)
: get all properties from target
-
zn.sets(target, values)
: set object to target
Class
Define Class
The class has static
、statics
、mixins
、properties
、events
、methods
five key word;
static
: true
or false
, default value is false
, if value is true
, the class is static class, can't be instantiated. If you new the class, the system will throw TypeError
.statics
: define class static property or method.mixins
: define Super Class collection.properties
: define class property, value is object.events
: define class event, value is array. init
is the constructor function for class.methods
: define class method, value is array.
Define Person Class
var Person = zn.Class({
static: false,
statics: {
count: 1
getCount: function (){
return this._count;
}
},
properties: {
name: '',
age: {
value: 10,
get: function (value){
this._age = value; (1)
},
set: function (){
return this._age;
}
}
},
methods: {
init: function (name, age){ (2)
console.log("I'm constructor function.");
this.name = name;
this.age = age;
},
say: function (){ (3)
console.log('person hello ', this.name);
return 'person hello ' + this.name;
}
}
});
var _count = Person.getCount();
console.log(_count);
var person1 = new Person('yangyxu', 20);
person1.name = "xu";
person1.set(name, "xu");
- define any property, the system will generate the
_
+ property_name property. init
is default constructor function, the name is fixed. Call new Person()
, init constructor function will be called;- define
say
customize method.
Define Student
var Student = zn.Class(Person, {
properties: {
grade: {
value: 10,
get: function (value){
this._grade = value; (1)
},
set: function (){
return this._grade;
}
}
},
methods: {
init: function (name, age, grade){ (2)
this.super(name, age);
this.sets({
name: name,
age: age,
grade: grade
});
},
say: function (){ (3)
this.super(name, age);
console.log('student hello ', this.name);
return 'student hello ' + this.name;
}
}
});
var _yangyxu = new Student('yangyxu', 20, 'g1');
_yangyxu.say();
Define Teacher
var Teacher = zn.Class(Person, {
properties: {
id: ''
},
methods: {
init: {
auto: true,
value: function (argv){ (2)
this.sets(argv);
}
},
teach: function (){
return 'teacher name: ' + this.name;
}
}
});
var _yangyxu = new Teacher('t1', 20);
_yangyxu.teach();
Define Module
Define module is using AMD.
Define zeanium module
zn.define([
'node:http'
], function (node_http){
return zn.Class({
properties: {
},
methods: {
}
});
});
Documentation
http://www.zeanium.com
License
MIT