From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../errors/cyclic_object_value/index.html | 8 ++++---- .../reference/errors/not_a_function/index.html | 22 +++++++++++----------- .../reference/errors/not_defined/index.html | 10 +++++----- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/errors') diff --git a/files/zh-cn/web/javascript/reference/errors/cyclic_object_value/index.html b/files/zh-cn/web/javascript/reference/errors/cyclic_object_value/index.html index 9ab3cb7b02..b729af45fa 100644 --- a/files/zh-cn/web/javascript/reference/errors/cyclic_object_value/index.html +++ b/files/zh-cn/web/javascript/reference/errors/cyclic_object_value/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Errors/Cyclic_object_value

提示信息

-
TypeError: cyclic object value (Firefox)
+
TypeError: cyclic object value (Firefox)
 TypeError: Converting circular structure to JSON (Chrome and Opera)
 TypeError: Circular reference in value argument not supported (Edge)
@@ -34,7 +34,7 @@ TypeError: Circular reference in value argument not supported (Edge)

在如下循环结构中:

-
var a = {};
+
var a = {};
 var b = {};
 a.child = b;
 b.child = a;
@@ -42,7 +42,7 @@ b.child = a;
 
 

{{jsxref("JSON.stringify()")}} 将会报错

-
JSON.stringify(a);
+
JSON.stringify(a);
 // TypeError: cyclic object value
 
@@ -52,7 +52,7 @@ b.child = a;

注意:以下代码并不会保存循环引用的值。

-
var seen = [];
+
var seen = [];
 
 var replacer = function(key, value) {
   if (typeof value === "object" && value !== null) {
diff --git a/files/zh-cn/web/javascript/reference/errors/not_a_function/index.html b/files/zh-cn/web/javascript/reference/errors/not_a_function/index.html
index fc4f664e1d..00c3cb3073 100644
--- a/files/zh-cn/web/javascript/reference/errors/not_a_function/index.html
+++ b/files/zh-cn/web/javascript/reference/errors/not_a_function/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Errors/Not_a_function
 
 

信息

-
TypeError: Object doesn't support property or method {x} (Edge)
+
TypeError: Object doesn't support property or method {x} (Edge)
 TypeError: "x" is not a function

错误类型

@@ -47,20 +47,20 @@ TypeError: "x" is not a function

函数的名称拼写错误,这种情况是经常发生的:

-
var x = document.getElementByID("foo");
+
var x = document.getElementByID("foo");
 // TypeError: document.getElementByID is not a function
 

正确的方法名应该是 getElementById:

-
var x = document.getElementById("foo");
+
var x = document.getElementById("foo");
 

调用Object类型中不存在的方法

对于某些特殊的方法,它只属于某些特定的原生对象中,你必须提供一个回调函数才能正常运行。例如:这里调用了一个 {{jsxref("Array.prototype.map()")}} 方法,但是这方法只能被 {{jsxref("Array")}} 对象所调用。 

-
var obj = { a: 13, b: 37, c: 42 };
+
var obj = { a: 13, b: 37, c: 42 };
 
 obj.map(function(num) {
   return num * 2;
@@ -70,7 +70,7 @@ obj.map(function(num) {
 
 

正确的做法,使用一个数组来代替:

-
var numbers = [1, 4, 9];
+
var numbers = [1, 4, 9];
 
 numbers.map(function(num) {
   return num * 2;
@@ -83,7 +83,7 @@ numbers.map(function(num) {
 
 

当您在创建类时,可能会存在某个属性和某个方法的名称相同,当您在调用该函数时,编译器会认为该函数不存在.

-
var Dog = function () {
+
var Dog = function () {
  this.age = 11;
  this.color = "black";
  this.name = "Ralph";
@@ -102,7 +102,7 @@ myNewDog.name("Cassidy"); //Uncaught TypeError: myNewDog.name is not a function
 
 

正确的做法是使用不同的变量名.

-
var Dog = function () {
+
var Dog = function () {
  this.age = 11;
  this.color = "black";
  this.dogName = "Ralph"; //Using this.dogName instead of .name
@@ -124,13 +124,13 @@ myNewDog.name("Cassidy"); //Dog { age: 11, color: 'black', dogName: 'Cassidy' }<
 
 

使用后者时将会抛出错误:

-
const sixteen = 2(3 + 5);
+
const sixteen = 2(3 + 5);
 alert('2 x (3 + 5) is ' + String(sixteen));
 //Uncaught TypeError: 2 is not a function

您可以添加乘法运算符 * 来改正代码:

-
const sixteen = 2 * (3 + 5);
+
const sixteen = 2 * (3 + 5);
 alert('2 x (3 + 5) is ' + String(sixteen));
 //2 x (3 + 5) is 16
@@ -140,7 +140,7 @@ alert('2 x (3 + 5) is ' + String(sixteen));

以下为一个示例模块 (helpers.js)

-
let helpers = function () { };
+
let helpers = function () { };
 
 helpers.groupBy = function (objectArray, property) {
   return objectArray.reduce(function (acc, obj) {
@@ -158,7 +158,7 @@ export default helpers;

在 App.js中正确导入该模块:

-
import helpers from './helpers'
+
import helpers from './helpers'

相关

diff --git a/files/zh-cn/web/javascript/reference/errors/not_defined/index.html b/files/zh-cn/web/javascript/reference/errors/not_defined/index.html index a092f394ec..cc5fadb2a8 100644 --- a/files/zh-cn/web/javascript/reference/errors/not_defined/index.html +++ b/files/zh-cn/web/javascript/reference/errors/not_defined/index.html @@ -7,7 +7,7 @@ translation_of: Web/JavaScript/Reference/Errors/Not_defined

错误信息

-
ReferenceError: "x" is not defined
+
ReferenceError: "x" is not defined
 

错误类型

@@ -26,19 +26,19 @@ translation_of: Web/JavaScript/Reference/Errors/Not_defined

变量没有被声明

-
foo.substring(1); // ReferenceError: foo is not defined
+
foo.substring(1); // ReferenceError: foo is not defined
 

“foo” 变量没有在任何地方被声明。它需要是某种字符串,这样 {{jsxref("String.prototype.substring()")}} 方法才可以正常工作。

-
var foo = 'bar';
+
var foo = 'bar';
 foo.substring(1); // "ar"

错误的作用域

变量必须是在它当前的执行环境中可用的。在一个函数(function)中定义的变量不能从这个函数外部的任何地方访问,因为这个变量的作用域仅在这个函数的内部。

-
function numbers () {
+
function numbers () {
   var num1 = 2,
       num2 = 3;
   return num1 + num2;
@@ -48,7 +48,7 @@ console.log(num1); // ReferenceError num1 is not defined.

然而,一个函数可用使用在它所被定义的作用域中的所有变量。换句话说,当一个函数被定义在全局作用域的时候,它可以访问所有在全局作用域中定义的变量。

-
var num1 = 2,
+
var num1 = 2,
     num2 = 3;
 
 function numbers () {
-- 
cgit v1.2.3-54-g00ecf