What does `get` mean in an object literal?

The following is a snippet from the Chrome Developer Tool:

WebInspector.DOMStorage.prototype = {
    get id()
    {
        return this._id;
    },

    get domain()
    {
        return this._domain;
    },

    get isLocalStorage()
    {
        return this._isLocalStorage;
    },

    getEntries: function(callback)
    {
        DOMStorageAgent.getDOMStorageEntries(this._id, callback);
    },

    setItem: function(key, value, callback)
    {
        DOMStorageAgent.setDOMStorageItem(this._id, key, value, callback);
    },

    removeItem: function(key, callback)
    {
        DOMStorageAgent.removeDOMStorageItem(this._id, key, callback);
    }
}

WebInspector.DOMStorageis a function, and in the code above its prototypes. The strangest thing for me is the following method: get id()or getsomething - I checked that only objects are recognized in the prototype of the object removeItem, getEntriesand setItem. What about others?

+3
source share
1 answer

These are getters. If you have an instance DOMStorage, you can do:

var domain = inst.domain;

but you cannot assign it (or you can, but the value does not change):

inst.domain = 4; #doesnt change inst.domain

See this link for more details . Only some browsers are supported.

+3
source

All Articles