如何访问匿名对象的属性?
$.post("test.php", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
对象 { name: "John", time: "2pm" }
是匿名的。 通常,我会使用类似于以下的语法访问对象的属性:
objectname.propertyname
但是当没有 objectname
时我该怎么办? 如何访问propertyname
?
$.post("test.php", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
The object { name: "John", time: "2pm" }
is anonymous. Normally, I would access the properties of an object using syntax similar to the following:
objectname.propertyname
But what can I do when there is no objectname
? How can I access propertyname
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
匿名对象的全部意义在于它就是匿名的。 它只能在上下文中访问。 如果稍后想访问该对象,则需要将该对象分配给变量。
尝试:
The whole point of an anonymous object is that it is just that, anonymous. It is accessed in context only. If you want to access the object later on, then you need to assign the object to a variable.
Try: