From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/glossary/expando/index.html | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 files/zh-cn/glossary/expando/index.html (limited to 'files/zh-cn/glossary/expando') diff --git a/files/zh-cn/glossary/expando/index.html b/files/zh-cn/glossary/expando/index.html new file mode 100644 index 0000000000..6cb121c0ff --- /dev/null +++ b/files/zh-cn/glossary/expando/index.html @@ -0,0 +1,34 @@ +--- +title: Expando +slug: Glossary/Expando +tags: + - JavaScript + - Reference + - expando +translation_of: Glossary/Expando +--- +

可扩展对象的动态属性(Expando properties)是{{glossary("JavaScript")}} 添加到{{glossary("DOM")}} 节点的属性 , 可以直接从 DOM 元素中访问。 这些属性不是{{glossary("对象")}} 的DOM 规范的一部分:

+ +
window.document.foo = 5; // foo 是一个自定义属性
+ +

该术语也可以应用于添加到对象的属性, 而不遵守对象的原始意图, 例如非数字命名的属性添加到一个{{glossary("数组")}}里.

+ +

注:
+ expando 可能是 expandable object 的缩写,表示可扩展的对象。expando property 表示可扩展对象的动态属性, 可以在运行时动态添加到对象中的属性 。
+ “JavaScript 中的所有对象均支持 expando 属性和方法,这些属性和方法可在运行时动态添加和移除。”(来源:MSDN)  

+ +

例子:二维数组的创建

+ +
var n = 5;
+var i, j;
+
+var arr = new Array(n);            //创建第一维的数组
+for (i = 0; i < n; i++)
+{
+    arr[i] = new Array(n);
+    for (j = 0; j < n; j++)        // 内循环创建第二维数组
+    {
+        arr[i][j] = i * j;         // 数组赋值
+    }
+}
+console.log(arr);
-- cgit v1.2.3-54-g00ecf