巩固javascript对象、方法和属性的知识
Solidifying knowledge of javascript objects, methods, and 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中,对象文字是一个对象的零对或多对属性名称和相关值的列表,用大括号({})括起来。
有关更多信息,您可以查看对象文字的MDN规范。
在你的情况下,如果你写:
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。
这是一个变量
var property
这是一个函数声明
function method() { };
这是一个对象类型的变量(以JSON格式声明),有2个属性。
var obj = {
property: "",
method: function() {}
};
同样的东西可以这样写,当然不是JSON:
var obj = new Object();
obj.property = "";
obj.method = function() {};
或
var obj = new function() {
this.property = "";
this.method = function() {};
}
等等,还有其他方法。
您的其他示例与上面的示例相同,例如,调用obj.method()
。method
是作为对象的obj
的成员,并且该成员的类型为function
。您可以通过调用typeof(obj.method)
对此进行测试,它应该返回'function'
。
相关文章:
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 全局变量和全局对象的属性之间有什么区别吗
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 序列化数据属性中对象的最可靠方法
- 分析高度属性时出现意外值{{specs.height}}.index.html
- TypeError:无法读取属性'推'未定义的JavaScript
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- AngularJS-使用'true'属性
- 可以't使用JavaScript获取width属性
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 如何使用javascript获取嵌套对象中所有子对象的单个属性
- JavaScript Pub/Sub属性访问问题
- 从JavaScript访问struts操作中的属性
- 是否可以从父类访问子类的属性
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何在选项卡上定义属性'的主窗口对象
- 锚点元素的href属性自动更改
- jQuery最近父级的数据属性选择器
- 巩固javascript对象、方法和属性的知识