Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

JavaScript nuance Method question

Hi All,

I am really trying to get an in depth understanding of OOP JavaScript.  I found this article with the code below.


unction User (theName, theEmail) {
    this.name = theName;
    this.email = theEmail;
    this.quizScores = [];
    this.currentScore = 0;
}
​
User.prototype = {
    constructor: User,
    saveScore:function (theScoreToAdd)  {
        this.quizScores.push(theScoreToAdd)
    },
    showNameAndScores:function ()  {
        var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet";
        return this.name + " Scores: " + scores;
    },
    changeEmail:function (newEmail)  {
        this.email = newEmail;
        return "New Email Saved: " + this.email;
    }
}

Open in new window


My question is about the methods created for the constructor, 'showNameAndScores', 'saveScore' and 'changeEmail'.

Lets look at 'showNameAndScores' as an example.

user.prototype.getProperty showNameAndScores = function() //takes a string propertyName. returns that property.
{
        var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet";
        return this.name + " Scores: " + scores;
}

Open in new window


vs.

    showNameAndScores:function ()  {
        var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet";
        return this.name + " Scores: " + scores;
    },

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

What is your question?
Avatar of Isaac

ASKER

Oh...sorry.

What's the difference between the two methods I have above?
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial