Skip to main content
Legend
October 14, 2013
Answered

Is the dollar ($) object extensible?

  • October 14, 2013
  • 1 reply
  • 630 views

Is it possible to add methods to ExtendScript $ object?  If yes, how might it be acheived?

This topic has been closed for replies.
Correct answer Arie Stavchansky

Okay, after some time, here is how I ended up implementing new methods on the $ object.  I assign an immediately executed function to a new property on the $ object.  Then I can have a namespaced function methods I can call with $.

In a separate file, say "utils.jsx", from my main ExtendScript code, I've got something like this (just a basic form):

($.className = function () {

  this.defaults = {

     prop1 : "apples",

     prop2 : "oranges",

     prop3 : "bananas"

  }

  this.firstMethod = function(words) {

     $.writeln("Now speaking: " + words);

  }

  return this;

}())

Then in my main ExtendScript code, I `#include` it, and begin to use the methods.  Something like this:

#include 'utils.jsx';

$.className.firstMethod("e pluribus unum"); //outputs to console: 'Now speaking: e pluribus unum'

1 reply

Arie StavchanskyAuthorCorrect answer
Legend
October 14, 2013

Okay, after some time, here is how I ended up implementing new methods on the $ object.  I assign an immediately executed function to a new property on the $ object.  Then I can have a namespaced function methods I can call with $.

In a separate file, say "utils.jsx", from my main ExtendScript code, I've got something like this (just a basic form):

($.className = function () {

  this.defaults = {

     prop1 : "apples",

     prop2 : "oranges",

     prop3 : "bananas"

  }

  this.firstMethod = function(words) {

     $.writeln("Now speaking: " + words);

  }

  return this;

}())

Then in my main ExtendScript code, I `#include` it, and begin to use the methods.  Something like this:

#include 'utils.jsx';

$.className.firstMethod("e pluribus unum"); //outputs to console: 'Now speaking: e pluribus unum'