From 85b59393e35b625d0650e60512ca508372cc3e99 Mon Sep 17 00:00:00 2001 From: 现阳 <43157411+meakle@users.noreply.github.com> Date: Sun, 5 Dec 2021 00:50:19 +0800 Subject: Fix syntax highlight Web/JavaScript/Reference/Global_Objects/BigInt, zh-CN (#3260) --- .../javascript/reference/global_objects/bigint/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'files/zh-cn/web') diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint/index.html b/files/zh-cn/web/javascript/reference/global_objects/bigint/index.html index 225cda75d6..5f625f83ad 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/bigint/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/BigInt
可以用在一个整数字面量后面加 n 的方式定义一个 BigInt ,如:10n,或者调用函数BigInt()。
const theBiggestInt = 9007199254740991n;
+const theBiggestInt = 9007199254740991n;
const alsoHuge = BigInt(9007199254740991);
// ↪ 9007199254740991n
@@ -34,12 +34,12 @@ const hugeBin = BigInt("0b11111111111111111111111111111111111111111111111111111"
使用 typeof 测试时, BigInt 对象返回 "bigint" :
-typeof 1n === 'bigint'; // true
+typeof 1n === 'bigint'; // true
typeof BigInt('1') === 'bigint'; // true
使用 Object 包装后, BigInt 被认为是一个普通 "object" :
-typeof Object(1n) === 'object'; // true
+typeof Object(1n) === 'object'; // true
运算
@@ -121,7 +121,7 @@ mixed.sort();
注意被 Object 包装的 BigInts 使用 object 的比较规则进行比较,只用同一个对象在比较时才会相等。
-0n === Object(0n); // false
+0n === Object(0n); // false
Object(0n) === Object(0n); // false
const o = Object(0n);
@@ -199,11 +199,11 @@ Boolean(12n)
对任何 BigInt 值使用 {{jsxref("JSON.stringify()")}} 都会引发 TypeError,因为默认情况下 BigInt 值不会在 JSON 中序列化。但是,如果需要,可以实现 toJSON 方法:
-BigInt.prototype.toJSON = function() { return this.toString(); }
+BigInt.prototype.toJSON = function() { return this.toString(); }
JSON.stringify 现在生成如下字符串,而不是抛出异常:
-JSON.stringify(BigInt(1));
+JSON.stringify(BigInt(1));
// '"1"'
例子
--
cgit v1.2.3-54-g00ecf