-1

I have a basic javascript question. This code seems to call a function inside the same function createEvent. But the function itself doesn't have any parameters inside, so how can it call the same function createEvent inside createEvent with the parameters title, start, and end?

function createEvent(calendarId) {
  var cal = CalendarApp.getCalendarById(calendarId);
  var title = 'Script Demo Event';
  var start = new Date("April 1, 2012 08:00:00 PDT");
  var end = new Date("April 1, 2012 10:00:00 PDT");
  var desc = 'Created using Google Apps Script';
  var loc = 'Script Center';

  var event = cal.createEvent(title, start, end, {
      description : desc,
      location : loc
  });
};

Can anyone here help me explain this?

1
  • 2
    createEvent and cal.createEvent are two different functions. Commented Oct 27, 2013 at 20:36

1 Answer 1

2

Your top-level createEvent has no scope, i.e. it belongs to no object, and therefore, it is completely different from the scoped function createEvent that apparently exists on a Calendar object of some sort. In short, these are not the same functions. The "inner" one is actually a member of another object.

I should point out, however, that with javascript, you can pass as many arguments as you'd like to any function. Just because the prototype lists a single argument does not limit the number of arguments you can pass. That does not apply in this particular situation, but it's good for you to know for future reference.

Sign up to request clarification or add additional context in comments.

1 Comment

You can pass only 255 arguments :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.