Package Exports
- zeanium
- zeanium/dist/znweb.minx.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zeanium) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 functionzn.idleArray()
: return empty arrayzn.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 valuezn.serializeJSON(jsonObject)
: serialize json datazn.fix(target, argv...)
: if target has no key in arguments key, the function will extend object arguments value to targetzn.extend(target, argv...)
: the function will extend object arguments value to targetzn.overwrite(target, argv...)
: get argv value to overwrite the target valuezn.path(target, path, value)
: set or get the value for the path in targetzn.invoke(target, path, args)
: args as arguments, invoke the target path functionzn.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 functionzn.clone(target)
: clone target to a copyzn.type(target)
: get type for targetzn.is(target, type)
: judge target type is or not typezn.may(target, name)
: judge target has "name" eventzn.can(target, name)
: judge target can exec "name" eventzn.has(target, name)
: judge target has "name" propertyzn.get(target, name)
: get "name" value from target objectzn.set(target, name, value)
: set value to target name propertyzn.gets(target)
: get all properties from targetzn.sets(target, values)
: set object to target
Class
Define Class
The class has static
、statics
、mixins
、properties
、events
、methods
five key word;
static
:true
orfalse
, default value isfalse
, if value istrue
, the class is static class, can't be instantiated. If you new the class, the system will throwTypeError
.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, //defalut value is false
statics: {
count: 1 //class static property,
getCount: function (){ //class static method,
return this._count;
}
},
properties: {
name: '', //define `name` property, value is ''
age: {
value: 10, //define `age` default value
get: function (value){ //define `age` get method
this._age = value; (1)
},
set: function (){ //define `age` set method
return this._age;
}
}
},
methods: {
init: function (name, age){ (2)
//If you new Person Class instance, init method will be call
console.log("I'm constructor function.");
this.name = name;
this.age = age;
//!important: This code will call 'age' set function
},
say: function (){ (3)
console.log('person hello ', this.name);
return 'person hello ' + this.name;
}
}
});
var _count = Person.getCount();
console.log(_count); //print: 1
var person1 = new Person('yangyxu', 20);
person1.name = "xu"; //<1>
person1.set(name, "xu");//<2>
//<1> is the same with <2>
- define any property, the system will generate the
_
+ property_name property. init
is default constructor function, the name is fixed. Callnew Person()
, init constructor function will be called;- define
say
customize method.
Define Student
var Student = zn.Class(Person, { //inherit Person, the Student Super is Person
properties: {
grade: {
value: 10, //define `age` default value
get: function (value){ //define `age` get method
this._grade = value; (1)
},
set: function (){ //define `age` set method
return this._grade;
}
}
},
methods: {
init: function (name, age, grade){ (2)
this.super(name, age); //It will call super Class Person init method
this.sets({
name: name,
age: age,
grade: grade
});
//
},
say: function (){ (3)
this.super(name, age); //It will call super Class Person say method
console.log('student hello ', this.name);
return 'student hello ' + this.name;
}
}
});
var _yangyxu = new Student('yangyxu', 20, 'g1');
_yangyxu.say();
//print:
//person hello yangyxu
//student hello yangyxu
Define Teacher
var Teacher = zn.Class(Person, { //inherit Person, the Student Super is Person
properties: {
id: ''
},
methods: {
init: {
auto: true, // the attr is the same with this.super();
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' //If module is node module, you have to add "node:" prefix
], function (node_http){ //If load finished, you can use the module.
return zn.Class({
properties: {
},
methods: {
}
});
});