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

巩固javascript对象、方法和属性的知识,javascript,object,methods,properties,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:fu

我只想巩固(确切地知道)什么是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?
这是一个变量

var属性

这是一个函数声明

函数方法(){}

这是一个object类型的变量(以JSON格式声明),具有2个属性

var obj = {
    property: "", 
    method: function() {}
};
同样的东西也可以这样写,当然不是JSON:

var obj = new Object();
obj.property = "";
obj.method = function() {};

等等,还有其他的方法


您的其他示例与上面相同,例如,调用
obj.method()
<代码>方法
是对象obj的成员,该成员的类型为
函数
。您可以通过调用
typeof(obj.method)
来测试这一点,它应该返回
'function'

事实上,在Javascript中,对象文本是一个包含零对或多对属性名和对象关联值的列表,用大括号({})括起来

您可以查看以了解更多信息

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

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
中的函数hold,我还不明白还有一件事需要解决,那就是方法命令大多是内置的还是自定义方法(不仅仅是标识符)?对不起,我不明白?你这么说是什么意思?你是说他们文档中的方法,比如
hasOwnProperty()
propertyEnumerable()
?它将是
window.i()
或直接使用
i()。是的,事实上,在javascript中,当您在全局范围(而不是在任何对象或函数中)中声明函数时,它将被保存在
窗口
对象中,因为它是全局范围。
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();