Classes in ExtendScript ( Object Orientation)

Participant ,
Sep 08, 2020

Copy link to clipboard

Copied

Is it possible to work with "true" Object Orientation in ExtendScript? I've tried to create classes and Objects with JS Synthax, but that won't work:

 

 

class Person {
    constructor(name, surname) {
        this.name = name;
        this.surname = surname;
    }
}

var person = new Person('Jack', 'Smith');
alert(person);

 

 

This only returns "invalid use of reserved word class".

 

What I am actually trying to do in the long run is to build an UI based on Objects. So, speaking in Pseudocode:

 

 

Class myUI {
constructor(group , dropdown1, text1  )
this.group = group (parameter)

this.dropdown1 = group.add(dropdownlist (parameter))

this.text1 = group.add(edittext (parameter))

}

...etc


myUI(group,dropdown,text);

 

 

Any Idea how something like this could work?

Adobe Community Professional
Correct answer by Tomas Sinkunas | Adobe Community Professional

ExtendScript is based on super old ECMA version 3.something. So to imitate a Class, you'd need to use the old way, like this:

 

function Person(name, surname){
	this.name = name;
	this.surname = surname;
}

var person = new Person('Jack', 'Smith');
alert(person);

 

TOPICS
How to, Scripting, SDK

Views

94

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Classes in ExtendScript ( Object Orientation)

Participant ,
Sep 08, 2020

Copy link to clipboard

Copied

Is it possible to work with "true" Object Orientation in ExtendScript? I've tried to create classes and Objects with JS Synthax, but that won't work:

 

 

class Person {
    constructor(name, surname) {
        this.name = name;
        this.surname = surname;
    }
}

var person = new Person('Jack', 'Smith');
alert(person);

 

 

This only returns "invalid use of reserved word class".

 

What I am actually trying to do in the long run is to build an UI based on Objects. So, speaking in Pseudocode:

 

 

Class myUI {
constructor(group , dropdown1, text1  )
this.group = group (parameter)

this.dropdown1 = group.add(dropdownlist (parameter))

this.text1 = group.add(edittext (parameter))

}

...etc


myUI(group,dropdown,text);

 

 

Any Idea how something like this could work?

Adobe Community Professional
Correct answer by Tomas Sinkunas | Adobe Community Professional

ExtendScript is based on super old ECMA version 3.something. So to imitate a Class, you'd need to use the old way, like this:

 

function Person(name, surname){
	this.name = name;
	this.surname = surname;
}

var person = new Person('Jack', 'Smith');
alert(person);

 

TOPICS
How to, Scripting, SDK

Views

95

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 08, 2020 0
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

ExtendScript is based on super old ECMA version 3.something. So to imitate a Class, you'd need to use the old way, like this:

 

function Person(name, surname){
	this.name = name;
	this.surname = surname;
}

var person = new Person('Jack', 'Smith');
alert(person);

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 1
Participant ,
Sep 08, 2020

Copy link to clipboard

Copied

Thanks Tomas, that seems to work great!

 

First test running fine:

 

var myPanel = new Window("palette","title",undefined);

var dropContent = ["Slideshow","Texttafel","Typo Big","Video Container"];

function myUI(group, dropdownlist,myFirstText){
	this.group = group;
	this.dropdownlist = dropdownlist;
     this.myFirstText = myFirstText;
}

var newRow = new myUI('group', 'dropdownlist,undefined,dropContent','edittext {text:\'bla\'}');

myPanel.add(newRow.myFirstText);

myPanel.center();
myPanel.show();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 08, 2020 0