Why arrow function not working in Script Include - Tokyo?

Rahman3
Tera Expert

Hey guys,

I am exited about the Tokyo new Ecmascript features and playing with creating classes in Script Includes etc and over all it is good and promising. However, I have realised that arrow functions are not working inside a class in Script Include. Is everyone having this issue and reasons for it? Arrow functions are working inside the Business Rules though. See the following class that works great except the arror function! This arror function doesn't compile:

getInfo2 = () => `${this.name} is ${this.age} years old!`;

@Earl Duque @Andrew Barnes - AJB any ideas please?

This is really important as using other libraries code will have arrow functions and without it we are back to olden times 😉

let Person = class Person {
	
	//#isPrivate; // Private field not supported yet
	
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

	// This works!
    getInfo() {
        return `${this.name} is ${this.age} years old!`;
    }
	
	// This has compile issue complains about the = sighn???
	getInfo2 = () => `${this.name} is ${this.age} years old!`;
};

 

1 ACCEPTED SOLUTION

That is just a linter error, one can save the record with that error. However it seems in scopes the only way Script Includes are recognized and included into a context is if those contain the Class.create() instruction. And this was like this since forever, not linked with ES12.

All in all, after creating Script Include Person containing code

var Person = Class.create();

Person = class {

	//#isPrivate; // Private field not supported yet

	constructor(name, age) {
		this.name = name;
		this.age = age;
	}

	// This works!
	getInfo() {
		return `${this.name} is ${this.age} years old!`;
	}

	// This has compile issue complains about the = sighn???
	getInfo2 = () => `${this.name} is ${this.age} years old!`;
};

find_real_file.png

I can successfully run

var p = new Person('N1', 35);

gs.debug(p.getInfo2());

in Scripts - Background:

find_real_file.png

View solution in original post

7 REPLIES 7

Vamsi Sreenivas
Giga Guru

Hi Rahman,

 

what is the scope of your script include?

 

I believe the new ES6+ works only in scoped applications given that Javascript mode is selected to ECMAScript 2021(ES12).

Please mark my answer as HELPFUL / CORRECT if this help to resolve your issue.

find_real_file.png

 

Regards,

Vamsi S

Hi,

It is scoped app mate. If I am that excited and have gone that far then it means I know at least that bit 😉

 

thanks for the reply.

 

-O-
Kilo Patron
Kilo Patron
class Person {
	
	//#isPrivate; // Private field not supported yet
	
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }

	// This works!
    getInfo() {
        return `${this.name} is ${this.age} years old!`;
    }
	
	// This has compile issue complains about the = sighn???
	getInfo2 = () => `${this.name} is ${this.age} years old!`;
};

works in Scripts - Background.

Isn't let Person = class Person ... redundant anyway?

-O-
Kilo Patron
Kilo Patron

Actually

let Person = class Person2 {...

or

let Person = class {...

also work.

So probably when converting

 let Person = class Person {...

a redefinition of Person conflict is (wrongly) detected?