0

I wanted to extend the Paragraph (type? class? object?) and add some repeating functions to it like:

Paragraph.prototype.isEmpty = function() {
    return this.getText().trim().length === 0;
};

ReferenceError: "Paragraph" is not defined. (line 23, file "Code")

or

DocumentApp.Paragraph.prototype.isEmpty = function() {
    return this.getText().trim().length === 0;
};

TypeError: Cannot read property "prototype" from undefined. (line 23, file "Code")

but none of these work. I put this code in a Code.gs file and tried to use it but the compiler says there is no such thing.

What is this thing actually and how can I add something to it?

Rubén
  • 34,714
  • 9
  • 70
  • 166
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
  • 1
    Related: [how to create custom functions in class range](https://stackoverflow.com/q/14424148/1595451) – Rubén Feb 01 '19 at 22:41
  • 1
    Related: [Are javascript objects “open” like Ruby?](https://stackoverflow.com/q/17330228/1595451) – Rubén Feb 02 '19 at 00:03
  • I don't understand why someone would upvote a question that appears to have been covered previously (several times, by all appearances).. – Tedinoz Feb 02 '19 at 02:15
  • @Tedinoz Mhmm why not? Not everyone is a Javascript expert and can come up with the proper wording to find the other questions. I didn't know it's a general problem with Google scripts. Sometimes it's just easier to ask and risk a duplicate than search for a couple of days with the wrong terms. – t3chb0t Feb 02 '19 at 04:12
  • Your reputation and time on StackOverflow is well beyond mine, but I decline to defer to you on this. Even you should know that your response is not an attitude that is encouraged. You would be aware of [Why are questions no longer being accepted from my account?](https://stackoverflow.com/help/question-bans) _and why it is necessary_. If experienced "old hands" aren't going to respect the 'rules', then we shouldn't be surprised by any decline in the quality of questions. – Tedinoz Feb 03 '19 at 06:42
  • @Tedinoz I'm not sure I can follow you. What attitude do you mean exactly and what rules? I also don't understand what your link has to do with my question. I also would like to remind you that comments are not the right place for such discussion but I can gladly talk about it with you in chat. – t3chb0t Feb 03 '19 at 06:57

0 Answers0