Below is a snippet from Chrome Developer's tool:
WebInspector.DOMS开发者_高级运维torage.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.DOMStorage
is a function and in the code above are its prototypes. The most strange for me is the following method: get id()
or get
something - I checked that into the object prototype only removeItem
, getEntries
and setItem
are recognized. What about the others?
Those are getters. If you have an instance of DOMStorage
you can do:
var domain = inst.domain;
but you can't assign to it (or you can but the value doesn't get changed):
inst.domain = 4; #doesnt change inst.domain
See this link for more info about it. Only some browsers support it.
精彩评论