Objects in JavaScript ES5. Code example open

Objects in JavaScript ES5. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
    var ford = Object.create({
        calculateDistancePerYear: function () {
            Object.defineProperty(this, 'distancePerYear', {
                value: Math.ceil(this.distance / this.age),
                enumerable: false,
                writable: false,
                configurable: false
            })
        }
    }, {
        name: {
            value: 'Ford',
            enumerable: true,
            writable: false,
            configurable: false
        },
        model: {
            value: 'Focus',
            enumerable: true,
            writable: false,
            configurable: false
        },
        year: {
            value: 2015,
            enumerable: true,
            writable: false,
            configurable: false
        },
        distance: {
            value: 120500,
            enumerable: true,
            writable: true,
            configurable: false
        },
        age: {
            enumerable: true,
            get: function () {
                console.log('Get age')
                return new Date().getFullYear() - this.year
            },
            set: function () {
                console.log('Set age')
            }
        }
    })

    ford.calculateDistancePerYear()

    for (var key in ford) {
        if (ford.hasOwnProperty(key)) {
            console.log(key, ford[key])
        }
    }

[readalso

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation