对象字面量中的“get”是什么意思?
下面是 Chrome 开发人员工具的片段:
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.DOMStorage
是一个函数,上面的代码是它的原型。对我来说最奇怪的是以下方法:get id()
或get
某些东西 - 我仅将其签入对象原型removeItem
,< code>getEntries 和 setItem
被识别。其他人呢?
Below is a snippet from Chrome Developer's 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.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些都是吸气剂。如果您有一个
DOMStorage
实例,您可以执行以下操作:但无法分配给它(或者可以分配,但值不会更改):
请参阅 此链接了解更多信息。只有部分浏览器支持。
Those are getters. If you have an instance of
DOMStorage
you can do:but you can't assign to it (or you can but the value doesn't get changed):
See this link for more info about it. Only some browsers support it.