Javascript Object getOwnPropertyDescriptors()

Introduction

Object.getOwnPropertyDescriptors() static method method performs on Object.getOwnPropertyDescriptor() on all own properties.

let book = {};/*ww w  .ja  v  a  2s.  c  o m*/
Object.defineProperties(book, {
    year_: {
        value: 2020
    },

    edition: {
        value: 1
    },

    year: {
        get: function() {
            return this.year_;
        },

        set: function(newValue) {
            if (newValue > 2020) {
                this.year_ = newValue;
                this.edition += newValue - 2020;
            }
        }
    }
});

console.log(Object.getOwnPropertyDescriptors(book));



PreviousNext

Related