From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/weakmap/set/index.html | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/weakmap/set') diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html b/files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html new file mode 100644 index 0000000000..9643d66bfd --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html @@ -0,0 +1,89 @@ +--- +title: WeakMap.prototype.set() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/set +tags: + - JavaScript + - Method + - WeakMap +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/set +--- +
{{JSRef}}
+ +

set() 方法根据指定的keyvalue在 WeakMap对象中添加新/更新元素。

+ +
{{EmbedInteractiveExample("pages/js/weakmap-prototype-set.html")}}
+ + + +

语法

+ +
wm.set(key, value);
+ +

参数

+ +
+
key
+
必须的。必须是对象。是要在WeakMap 对象中添加元素的key部分。
+
value
+
必须的。任意的值。是要在WeakMap 对象中添加/元素的value部分。
+
+ +

返回值

+ +

WeakMap对象

+ +

例子

+ +

使用set方法

+ +
var wm = new WeakMap();
+var obj = {};
+
+// Add new elements to the WeakMap
+wm.set(obj, "foo").set(window, "bar"); // chainable
+
+// Update an element in the WeakMap
+wm.set(obj, "baz");
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-weakmap.prototype.set', 'WeakMap.prototype.set')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-weakmap.prototype.set', 'WeakMap.prototype.set')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容

+ + + +

{{Compat("javascript.builtins.WeakMap.set")}}

+ +

Firefox-特殊说明

+ + + +

See also

+ + -- cgit v1.2.3-54-g00ecf