javascript - Javascript 中的对象属性和对象属性有什么区别?

标签 javascript

我在 JavaScript 中看到过两个关于对象的术语,一个是它的属性,另一个是它的属性。这些术语之间有什么区别?

Each data property (object property that store data) has not only the name-value pair, but also 3 attributes (the three attributes are set to true by default):

  • Configurable Attribute: Specifies whether the property can be deleted or changed.
  • Enumerable: Specifies whether the property can be returned in a for/in loop.
  • Writable: Specifies whether the property can be changed.

原始上下文:http://javascriptissexy.com/javascript-objects-in-detail/

最佳答案

什么是 Javascript 中的属性和属性?

一般来说,attribute 和 property 是相同的。两者都表示质量,用技术术语来说就是键值对,所以键是属性/属性的名称,而值只不过是值。

有什么区别?

差异在于上下文而不是含义。

为什么使用两个术语?

因为即使是对象的属性也可能具有 property ,这被称为属性。

Javascript 中对象的属性是什么?

除了Object的属性之外,Object还有三个属性。 它们是原型(prototype)可扩展

例如:

var SampleObject  = { Name : "ObjName", id : "0"} // user created

实际对象的结构:

         var SampleObject = {class :someValue, // Attribute
                    prototype : someValue, // Attribute
                    extensible : someValue, // Attribute
                    Name : "ObjName", // Property 
                    id : "0"   // Property 
                     }

Javascript 中对象的属性是什么?

对象中的所有键值对都是对象的属性。

JavaScript 中对象的所有属性都有哪些属性?

对象的每个属性都具有以下 3 个属性。 可配置可枚举可写,这些值为 bool 值。

//Ex : 
var SampleObject = { key1 :{ p1 : "v1"}} // user created

//Actual Structure :

var SampleObject = { class :someValue, // Attribute
                     prototype : someValue, // Attribute
                     extensible : someValue, // Attribute
                     key1  : { Configurable : true, // attribute
                              Enumerable   : true, // attribute
                              Writable     : true  // attribute
                              p1           : "v1"  //property
                              }     // proeperty            
                   }

关于javascript - Javascript 中的对象属性和对象属性有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38017119/

相关文章:

javascript - Lotus Notes Xpage - view.postScript ("window.open()") 在替换包含的页面名称后不打开新窗口(仅在特定文档中)

c# - C# 和 JavaScript 正则表达式之间的区别?

javascript - 查找相对于字符串中给定位置左侧第一次出现的空格

javascript - 计算 javascript 输入类型=文本

javascript - jquery ajax post 和 axios post 的区别

javascript - 如何调整 flexslider 的大小?

php - 如何使用PHP和MySQL显示时间倒计时

javascript - AngularJS - 三向绑定(bind)

javascript - 如何将这些 'if' 语句转换为算法

javascript - 设置变量后运行 Javascript 函数