You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example using $$class.Constructor<TInstance> and create<TInstance, TConstructor>()
// Declare class type with read/write and read-only members.typeMyClass={value1: number; value2: number;}&Readonly<{getSum(): number;}>&$$class.JSProto;// Create the class
export constMyClass: $$class.Constructor<MyClass>=(function(): $$class.Constructor<MyClass>{varMyClass: $$class.Constructor<MyClass>=Class.create<MyClass, $$class.Constructor<MyClass>>();MyClass.prototype={value1: 1,value2: 2,getSum: function(this: MyClass){returnthis.value1+this.value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass();myClass.value1=9;myClass.value2=3;gs.info(myClass.getSum());
Example using $$class.Constructor<TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
// Declare class type with read-only public members.typeMyClass=Readonly<{getValue1(): number;setValue1(value: number): void;getValue2(): number;setValue2(value: number): void;getSum(): number;}>&$$class.JSProto;// Declare the prototype as the class type with the private members added.typeMyClassPrototype={_value1: number;
_value2: number;}&MyClass;// Create the class
export constMyClass: $$class.Constructor<MyClass,MyClassPrototype>=(function(): $$class.Constructor<MyClass,MyClassPrototype>{varMyClass: $$class.Constructor<MyClass,MyClassPrototype>=Class.create<MyClass,$$class.Constructor<MyClass, MyClassPrototype>,MyClassPrototype>();MyClass.prototype={
_value1: 1,_value2: 2,getValue1: function(this: MyClassPrototype): number{returnthis._value1;},setValue1: function(this: MyClassPrototype,value: number): void{ this._value1=isNaN(value) ? 0 : value;},getValue2: function(this: MyClassPrototype): number{returnthis._value2;},setValue2: function(this: MyClassPrototype,value: number): void{this._value2=isNaN(value) ? 0 : value;},getSum: function(this: MyClassPrototype){returnthis._value1+this._value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass();myClass.setValue1(9);myClass.setValue2(3);gs.info(myClass.getSum());
Example using Constructor1<TArg, TInstance> and create<TInstance, TConstructor>()
// Declare class type with read/write and read-only members.typeMyClass={value1: number;
value2: number;}&Readonly<{getSum(): number;}>&$$class.JSProto;// Create the class
export constMyClass: $$class.Constructor1<number,MyClass>=(function(): $$class.Constructor1<number,MyClass>{varMyClass: $$class.Constructor1<number,MyClass>=Class.create<MyClass,$$class.Constructor1<number,MyClass>>();// Cast the prototype since we won't be setting _value1 until the initialize method is called.MyClass.prototype=<MyClass&$$class.IPrototype1<number>>{value2: 0,initialize: function(this: MyClass,value1: number){this.value1=value1;},getSum: function(this: MyClass){returnthis.value1+this.value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass(9);myClass.value2=3;gs.info(myClass.getSum());
Example using Constructor1<TArg, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
// Declare class type with read-only public members.typeMyClass=Readonly<{getValue1(): number;setValue1(value: number): void;getValue2(): number;setValue2(value: number): void;getSum(): number;}>&$$class.JSProto;// Declare the prototype as the class type with the private members added.typeMyClassPrototype={_value1: number;
_value2: number;}&MyClass;// Create the class
export constMyClass: $$class.Constructor1<number,MyClass,MyClassPrototype>=(function(): $$class.Constructor1<number,MyClass,MyClassPrototype>{varMyClass: $$class.Constructor1<number,MyClass,MyClassPrototype>=Class.create<MyClass,$$class.Constructor1<number,MyClass,MyClassPrototype>,MyClassPrototype>();// Cast the prototype since we won't be setting _value1 until the initialize method is called.MyClass.prototype=<MyClassPrototype&$$class.IPrototype1<number>>{_value2: 0,initialize: function(this: MyClassPrototype,value1: number){this._value1=isNaN(value1) ? 0 : value1;},getValue1: function(this: MyClassPrototype): number{returnthis._value1;},
setValue1: function(this: MyClassPrototype,value: number): void{this._value1=isNaN(value) ? 0 : value;},getValue2: function(this: MyClassPrototype): number{returnthis._value2;},setValue2: function(this: MyClassPrototype,value: number): void{ this._value2=isNaN(value) ? 0 : value;},
getSum: function(this: MyClassPrototype){returnthis._value1+this._value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass(9);myClass.setValue2(3);gs.info(myClass.getSum());
Example using Constructor1Opt<TArg, TInstance> and create<TInstance, TConstructor>()
// Declare class type with read/write and read-only members.typeMyClass={value1: number;
value2: number;}&Readonly<{getSum(): number;}>&$$class.JSProto;// Create the class
export constMyClass: $$class.Constructor1Opt<number,MyClass>=(function(): $$class.Constructor1Opt<number,MyClass>{varMyClass: $$class.Constructor1Opt<number,MyClass>=Class.create<MyClass,$$class.Constructor1Opt<number,MyClass>>();// Cast the prototype since we won't be setting _value1 until the initialize method is called.MyClass.prototype=<MyClass&$$class.IPrototype1Opt<number>>{value2: 0,initialize: function(this: MyClass,value1?: number){this.value1=(typeofvalue1==='number') ? value1 : 0;},getSum: function(this: MyClass){returnthis.value1+this.value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass();myClass.value1=9;myClass.value2=3;gs.info(myClass.getSum());myClass=newMyClass(9);myClass.value2=3;gs.info(myClass.getSum());
Example using Constructor1Opt<TArg, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
// Declare class type with read-only public members.typeMyClass=Readonly<{getValue1(): number;setValue1(value: number): void;getValue2(): number;setValue2(value: number): void;getSum(): number;}>&$$class.JSProto;// Declare the prototype as the class type with the private members added.typeMyClassPrototype={_value1: number;
_value2: number;}&MyClass;// Create the class
export constMyClass: $$class.Constructor1Opt<number,MyClass,MyClassPrototype>=(function(): $$class.Constructor1Opt<number,MyClass,MyClassPrototype>{varMyClass: $$class.Constructor1Opt<number,MyClass,MyClassPrototype>=Class.create<MyClass,$$class.Constructor1Opt<number,MyClass,MyClassPrototype>,MyClassPrototype>();// Cast the prototype since we won't be setting _value1 until the initialize method is called.MyClass.prototype=<MyClassPrototype&$$class.IPrototype1Opt<number>>{_value2: 0,initialize: function(this: MyClassPrototype,value1?: number){this._value1=(typeofvalue1!=='number'||isNaN(value1)) ? 0 : value1;},getValue1: function(this: MyClassPrototype): number{returnthis._value1;},
setValue1: function(this: MyClassPrototype,value: number): void{this._value1=isNaN(value) ? 0 : value;},getValue2: function(this: MyClassPrototype): number{returnthis._value2;},setValue2: function(this: MyClassPrototype,value: number): void{ this._value2=isNaN(value) ? 0 : value;},
getSum: function(this: MyClassPrototype){returnthis._value1+this._value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass();myClass.setValue1(9);myClass.setValue2(3);gs.info(myClass.getSum());myClass=newMyClass(9);myClass.setValue2(3);gs.info(myClass.getSum());
Example using Constructor2<TArg1, TArg2, TInstance> and create<TInstance, TConstructor>() with static members
// Declare class type with read/write and read-only members.typeMyClass={value1: number;
value2: number;}&Readonly<{getSum(): number;}>&$$class.JSProto;// Declare constructor with static methodstypeMyClassConstructor=$$class.Constructor2<number,string,MyClass>&{getDifference(value1: number,value2: number): number;};// Create the classexportconstMyClass: MyClassConstructor=(function(): MyClassConstructor{varMyClass: MyClassConstructor=Class.create<MyClass,MyClassConstructor>();// Cast the prototype since we won't be setting value1 or value2 until the initialize method is called.
MyClass.prototype=<MyClass&$$class.IPrototype2<number,string>>{initialize: function(this: MyClass,value1: number,value2: string){this.value1=value1;this.value2=parseInt(value2);if(isNaN(this.value2))this.value2=0;},getSum: function(this: MyClass){returnthis.value1+this.value2;},type: "MyClass"};MyClass.getDifference=function(value1: number,value2: number){returnvalue1-value2;};returnMyClass;})();varmyClass=newMyClass(9,"3");gs.info(myClass.getSum());gs.info(MyClass.getDifference(9,3));
Example using Constructor2<TArg1, TArg2, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
// Declare class type with read-only public members.typeMyClass=Readonly<{getValue1(): number;setValue1(value: number): void;getValue2(): string;setValue2(value: string): void;getSum(): number;}>&$$class.JSProto;// Declare the prototype as the class type with the private members added.typeMyClassPrototype={_value1: number;
_value2: number;}&MyClass;// Create the class
export constMyClass: $$class.Constructor2<number,string,MyClass,MyClassPrototype>=(function(): $$class.Constructor2<number,string,MyClass,MyClassPrototype>{varMyClass: $$class.Constructor2<number,string,MyClass,MyClassPrototype>=Class.create<MyClass,$$class.Constructor2<number,string,MyClass,MyClassPrototype>,MyClassPrototype>();// Cast the prototype since we won't be setting _value1 or _value2 until the initialize method is called.MyClass.prototype=<MyClassPrototype&$$class.IPrototype2<number,string>>{_value2: 0,initialize: function(this: MyClassPrototype,value1: number,value2: string){this._value1=(typeofvalue1!=='number'||isNaN(value1)) ? 0 : value1;this._value2=parseInt(value2);if(isNaN(this._value2))this._value2=0;},getValue1: function(this: MyClassPrototype): number{returnthis._value1;},
setValue1: function(this: MyClassPrototype,value: number): void{this._value1=isNaN(value) ? 0 : value;},getValue2: function(this: MyClassPrototype): string{return''+this._value2;},setValue2: function(this: MyClassPrototype,value: string): void{
this._value2=parseInt(value);if(isNaN(this._value2))this._value2=0;},
getSum: function(this: MyClassPrototype){returnthis._value1+this._value2;},type: "MyClass"};returnMyClass;})();varmyClass=newMyClass(9,"3");gs.info(myClass.getSum());
Example using Constructor2Opt1<TArg1, TArg2, TInstance> and create<TInstance, TConstructor>()
Example using Constructor2Opt1<TArg1, TArg2, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
Example using Constructor2Opt<TArg1, TArg2, TInstance> and create<TInstance, TConstructor>()
Example using Constructor2Opt<TArg1, TArg2, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
Example using Constructor3<TArg1, TArg2, TArg3, TInstance> and create<TInstance, TConstructor>()
Example using Constructor3<TArg1, TArg2, TArg3, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
Example using Constructor3Opt1<TArg1, TArg2, TArg3, TInstance> and create<TInstance, TConstructor>()
Example using Constructor3Opt1<TArg1, TArg2, TArg3, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
Example using Constructor3Opt2<TArg1, TArg2, TArg3, TInstance> and create<TInstance, TConstructor>()
Example using Constructor3Opt2<TArg1, TArg2, TArg3, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
Example using Constructor3Opt<TArg1, TArg2, TArg3, TInstance> and create<TInstance, TConstructor>()
Example using Constructor3Opt<TArg1, TArg2, TArg3, TInstance, TPrototype> and create<TInstance, TConstructor, TPrototype>()
Example using ConstructorN<TInstance> and create<TInstance, TConstructor>()
Example using ConstructorN<TInstance, TPrototype and create<TInstance, TConstructor, TPrototype>()