javascript - 巩固 JavaScript 对象、方法和属性的知识

标签 javascript object methods properties

我只是想固化(确定)什么是js对象、方法和属性。到目前为止,这是我自己的观点,但我几乎没有怀疑,这就是为什么我来这里是为了了解并证明我需要的是真实的。

var property= "is this a property?";
function method(){"is this a method?"};
var ObjectLiteral = {property:"this should be a property of this ObjectLiteral I guess", method:function(){"this should be a method of ObjectLiteral am I right?"}};

//Here is the cache:

var Cachie = {method : function SecondObject(){/*nothing in here just a regular function or object*/},objecto:function(){alert("is this a method or object of Cachie object if so methods and properties are functions and variables")}};
Cachie.objecto();//than what is objecto related to Cachie and what is objecto called related Cachie is it an object of Cachie by the way, or is just simply called an object and nothing else of Cachie whatsoever?

最佳答案

事实上,在 Javascript 中,对象字面量是对象的零对或多对属性名称和关联值的列表,括在大括号 ({}) 中。

您可以看看The MDN Specification for Object Literals欲了解更多信息。

在你的情况下,如果你写:

var Cachie = {method : function SecondObject(){/*nothing in here just a regular function or object*/},objecto:function(){alert("is this a method or object of Cachie object if so methods and properties are functions and variables")}};
Cachie.objecto();

意味着:

您有一个名为 Cachie 的文字对象,它具有两个属性:methodobjecto,它们是此处的函数,用于回答您的问题objecto 与 Cachie 相关是什么?objectoCachie 对象的函数和属性。

因此,当您调用 Cachie.objecto() 时,您只需调用对象 Cachie 的属性 objecto 中的函数。

关于javascript - 巩固 JavaScript 对象、方法和属性的知识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36304683/

相关文章:

java - 如何修复 Poker Deck 使其不重新实例化并将其限制为一副牌中只有 52 张牌?

javascript - 使用 greasemonkey 脚本自动化 flash 应用程序

javascript - 迭代时的奇怪行为

javascript - 时间轴上的鱼眼效果

javascript - 用两个不同的列包装一些 div

javascript - 在属性中查找数组中具有最高值的对象的索引

java - 为什么我不能在任何方法之外创建对象

java - 如何从另一个类(java)访问主类的变量?

python变量方法名

c++ - 在 C++ 中复制构造函数以供以后在函数中使用