1

Im creating an object and pushing to an array this.reminders , but an undefined is also gets push why is that? This code will give me work [ { description: 'Get to work in time', set_title: 'work related' }, undefined ]

   var ReminderSet = function(set_name) {
        this.set_name = set_name; 
        this.reminders = [];
    };

    ReminderSet.prototype.add = function(reminder, title) {
        this.reminders.push(reminder, title);
        console.log(this.set_name, this.reminders)

    };

    ReminderSet.prototype.list = function() {
        console.log(this.reminders); 
    };

    var Reminder = function(description,set_title) {
        this.description = description;
        this.set_title = set_title;
        //Describes the reminder
    };

var work = new ReminderSet("work")
          .add(new Reminder("Get to work in time", "work related"));
1
  • well, your add method pushes in reminder and title, but your your code calls it with a new Reminder object, and no title ;) Commented Oct 19, 2017 at 7:46

1 Answer 1

3

Your add() method takes two parameters:

ReminderSet.prototype.add = function(reminder, title) { /*...*/ }

But you're passing only one (i.e. a Reminder object):

var work = new ReminderSet("work")
      .add(new Reminder("Get to work in time", "work related"));

This causes the second parameter to be undefined.

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

Comments

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.