2

Full code block:

var create = {
    man: function(height) { // What is this line called?
        return "Generating a man. Who is " + height + " tall."
    },
    woman: function() { // And this one?
        return "Generating a woman.";
    }
};

var manC = create.man('2 feet');
console.log(manC);

Are they simply another way to create a function?

For clarification purposes, I do know what this code does.

1
  • It's the same thing as in create.man = function(height){…}; Commented Nov 14, 2013 at 23:58

3 Answers 3

3

It's called an "object literal". In your example, "man" and "woman" are two properties of the instantiated object. The values of the properties are functions.

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

Comments

0

What's it called? I'd say it's called defining an unnamed function within an object context. The difference between that syntax (using colons) and others you might see with equals signs is just the context in which you're defining your methods.

Comments

0

Lines you ask for are actually properties of object to which you've assigned anonymous functions.

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.