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 --- .../web/javascript/reference/operators/instanceof/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/operators/instanceof') diff --git a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html index a1e3c5a538..9bc5622462 100644 --- a/files/zh-cn/web/javascript/reference/operators/instanceof/index.html +++ b/files/zh-cn/web/javascript/reference/operators/instanceof/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof

语法

-
object instanceof constructor
+
object instanceof constructor

参数

@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Operators/instanceof

instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。

-
// 定义构造函数
+
// 定义构造函数
 function C(){}
 function D(){}
 
@@ -87,7 +87,7 @@ o3 instanceof C; // true 因为 C.prototype 现在在 o3 的原型链上
 
 

但是,使用对象文字符号创建的对象在这里是一个例外:虽然原型未定义,但 instanceof Object 返回 true

-
var simpleStr = "This is a simple string";
+
var simpleStr = "This is a simple string";
 var myString  = new String();
 var newStr    = new String("String created with constructor");
 var myDate    = new Date();
@@ -113,7 +113,7 @@ myDate instanceof String;   // 返回 false

下面的代码创建了一个类型 Car,以及该类型的对象实例 mycar. instanceof 运算符表明了这个 mycar 对象既属于 Car 类型,又属于 Object 类型。

-
function Car(make, model, year) {
+
function Car(make, model, year) {
   this.make = make;
   this.model = model;
   this.year = year;
@@ -128,13 +128,13 @@ var b = mycar instanceof Object; // 返回 true
 
 

要检测对象不是某个构造函数的实例时,你可以这样做

-
if (!(mycar instanceof Car)) {
+
if (!(mycar instanceof Car)) {
   // Do something, like mycar = new Car(mycar)
 }

这和以下代码完全不同

-
if (!mycar instanceof Car)
+
if (!mycar instanceof Car)

这段代码永远会得到 false!mycar 将在 instanceof 之前被处理,所以你总是在验证一个布尔值是否是 Car 的一个实例)。

-- cgit v1.2.3-54-g00ecf