1

With Indesign scripting, why can't I add properties to an object? I get an error

Object does not support the property or method 'foo'

items = b.items(b.layer("s_labels"));

for (var i = 0; i < items.length; i++) {
    items[i].fit(FitOptions.frameToContent);

    items[i].foo = "bar";
    // other attempt
    items[i]["foo"] = "bar";
}
fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
clankill3r
  • 9,146
  • 20
  • 70
  • 126

1 Answers1

3

I guess you simply are not allowed to add new fields or methods to javascript objects that are provided by InDesign.

  • I think more of it as a JS API to the InDesign DOM. What you could do is passing JSON to a label and evaluate it later. `item[i].label = JSON.stringify({foo:"bar"});var obj = JSON.parse(item[i].label);` – fabianmoronzirfas Nov 19 '14 at 18:50
  • right, if you just want to attach information then fields like label could be a good starting point to hack something together! – Ludwig Zeller Nov 25 '14 at 13:53