ZenClass
所需的关键词
声明例子
zenClass MyClass { // 声明一个叫做 MyClass 的类
zenConstructor(arg as string, arg1 as int) { // 声明构造函数
myValue = arg;
myValueTwo = arg1;
// 一般这里填的都是给新的实例设置字段值
print("new MyClass");
}
zenConstructor(arg as string) { // 你可以声明多个构造函数,但不可互相调用,而且参数表不能相同。
myValue = arg;
myValueTwo = 25;
}
// 设置该类的字段
val myValue as string; // 在这里你可以不设初值,而在构造函数内给其赋值
val myValueTwo as int;
var myValueThree as int;
static myStaticValue as int = 233;
// 声明该类的叫做 getMyValue 的方法,返回字符串
function getMyValue() as string {
return this.myValue; // this指代该对象,这行即为返回该对象的 myValue 字段的值
}
function setMyValueThree(arg as int) as MyClass {
this.myValueThree = arg; // 由于 myValueThree 字段由 var 关键词声明,可以多次赋值
return this; // 返回该对象本身
}
function method() as string {
return this.myValue ~ this.myValueTwo;
}
}使用例子
最后更新于