Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development Game Development with Phaser Building a Breakout Game with Phaser Phaser Project Setup

Object Literal Shorthand Syntax

Having completed all of the prerequisites for this course, I havenโ€™t come across an object literal being defined without the key/property - value format as we see here in the code below for the object literal assigned to the scene key/property:

const config = {
    type: Phaser.AUTO,
    parent: 'game',
    width: 1280,
    height: 720,
    scale: {
        mode: Phaser.Scale.FIT,
    },
    scene: {
        preload,
        create,
        update,
    },
}

new Phaser.Game(config);


function preload() {}
function create() {}
function update() {}

After looking into the MDN docs, I came across the shorthand syntax for defining object literals. Is that what this is? So, the above code for the scene property equates to the following? :

scene: {
    preload: preload,
    create: create,
    update: update,
}

1 Answer

Steven Parker
Steven Parker
231,236 Points

That's exactly right. The variable name is optional when it is exactly the same as the keyword.