• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

What does "new" do?

Engaged ,
Sep 28, 2017 Sep 28, 2017

Copy link to clipboard

Copied

A lot of code snippets I find seem to have "new" in it. I'm trying to figure out exactly what it does. I've been googling and can't seem to really figure it out. I've tested a lot of things with and without "new" and it doesn't seem to make a difference. For example, these to lines of code both work with or without "new". So is "new" really needed and if so why?

app.activeDocument.activeLayer.translate(new UnitValue(1000,'px'),new UnitValue(1000,'px'));

app.activeDocument.activeLayer.translate(UnitValue(1000,'px'),UnitValue(1000,'px'));

TOPICS
Actions and scripting

Views

685

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
community guidelines
Adobe
Guest
Sep 29, 2017 Sep 29, 2017

Copy link to clipboard

Copied

According to the official JAVASCRIPT TOOLS GUIDE documentation:

https://wwwimages2.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf

page 230:

The UnitValue constructor creates a new UnitValue object. The keyword new is optional:

myVal = new UnitValue (value, unit);

myVal = new UnitValue ("value unit");

myVal = new UnitValue (value, "unit");

[...]

For example, all the following formats are equivalent:

myVal = new UnitValue (12, "cm");

myVal = new UnitValue ("12 cm");

myVal = UnitValue ("12 centimeters");

HTH...

Votes

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
community guidelines
Community Expert ,
Sep 29, 2017 Sep 29, 2017

Copy link to clipboard

Copied

Votes

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
community guidelines
Enthusiast ,
Sep 30, 2017 Sep 30, 2017

Copy link to clipboard

Copied

LATEST

You should use "new" when you want create instance of class.

new operator - JavaScript | MDN

Votes

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
community guidelines