我只是想固化(确定)什么是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
的文字对象,它具有两个属性:method
和 objecto
,它们是此处的函数,用于回答您的问题objecto 与 Cachie 相关是什么?,objecto
是 Cachie
对象的函数和属性。
因此,当您调用 Cachie.objecto()
时,您只需调用对象 Cachie
的属性 objecto
中的函数。
关于javascript - 巩固 JavaScript 对象、方法和属性的知识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36304683/