how to use javascript Object.defineProperty

I looked around for how to use the Object.defineProperty method, but couldn’t find anything decent.

Someone gave me this snippet of code:

Object.defineProperty(player, "health", {
    get: function () {
        return 10 + ( player.level * 15 );
    }
})

But I don’t understand it. Mainly, the get is what I can’t get (pun intended). How does it work?

10 Answers
10

Leave a Comment