Skip to main content
Inspiring
February 1, 2011
Question

Extending Document Object in CS5

  • February 1, 2011
  • 2 replies
  • 860 views

I would like to extend the Document object (or any other, for that matter) as described in this thread:

     http://forums.adobe.com/message/1103689#1103689

I tried extending Application with myOwnMethod as described, but even that doesn't work.  When I "alert" the extended function, it prints the implementation code of the procedure!  Here's the code:

Application.prototype.myOwnMethod = function() {
    return "Test String proto"
}

    alert(app.myOwnMethod)

When run, the alert box contains:

    function() {

        return "Test String proto"

}

What do I do to extend the Document or Application objects?

This topic has been closed for replies.

2 replies

Participant
February 1, 2011

It's also clear...

app.myOwnMethod - is just a variable contents "function() {return "Test String proto"}", and

app.myOwnMethod(); - calls your function

Harbs.
Legend
February 1, 2011

One word:

Don't!

I've never tried in Illustrator, but trying to extend native objects is more trouble than it's worth in InDesign. I imagine the same thing applies to Illustrator.

You are not invoking your method. To get your example to work the way you want you need to add the parenthesis:

alert(app.myOwnMethod())

Harbs

Big_RAAuthor
Inspiring
February 1, 2011

Can you point me somewhere that explains "Don't!"  What kind of trouble?  Why is this any worse than having to use javascript at all?

Harbs.
Legend
February 1, 2011

Search the InDesign scripting forum.

We've had quite a bit of discussion on prototyping objects in general, and InDesign objects in particular.

You should find plenty of food for thought there...

The absolute worst thing to do is to prototype "Object". Native objects can sometimes be prototyped and sometimes not. (For example InDesign collection objects can only be prototyped if they are previously invoked. I've never tried in Illy.) If there's any chance of scripts effecting other scripts, you're asking for trouble by prototyping any global objects.

Harbs