0
function Account(password, email)
{
    this.password=password;
    this.email=email;
}

function createAccount()
{
    var username="Moshiko22";
    var password="1112"
    var email="[email protected]";
    username=new Account(password, email);
}

The first function is a constructor. Assuming 'username', 'password' are user entered, I want to create an account object with the name the USER entered. (as in the object would be the 'username' the user has entered). I know why what I've done doesn't work, but I don't know how to actually get it done. Thanks in advance!

Sorry for being unclear: the user enters username, password and email. the password and email are just 2 properties in the object 'Account'. The username is what I want as the object itself.

1
  • 1
    It's really unclear what you're asking. In one place you talk about username and password, but in another place you're using password and email...? Commented Feb 27, 2013 at 15:32

2 Answers 2

5

Sounds like you want an object with the keys being the username?

var users = {};
function createAccount()
{
    var username="Moshiko22";
    var password="1112"
    var email="[email protected]";
    users[username] = new Account(password, email);
}
Sign up to request clarification or add additional context in comments.

Comments

-1

Like this:

function Account(password, email)
{
    this.constructor = function (password, email) {
        this.password=password;
        this.email=email;
    }.apply(this, arguments);
}

And then :

var account = new Account("mypwd", "[email protected]");

1 Comment

Even if it would have anything to do with the question, why are you modifying the constructor ins such a function? The whole inner function seems to be superfluous.

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.