- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我读到 MDN 上的 try catch(e if e instanceof ...) block ,但是,在 Node.js 中尝试时,我得到一个 SyntaxError: Unexpected token if。
如果这不起作用,是否有另一种方法来捕获特定异常,而不是可能发生的一切?
最佳答案
引用您链接到的 MDN 文档:
Note: This functionality is not part of the ECMAScript specification.
和
JavaScript 1.5, NES 6.0: Added multiple catch clauses (Netscape extension).
所以:不,这在 Node.js 中是不可能的。当然,您可以使用以下语法作为解决方法:
try {
try_statements
} catch (e) {
if (e instanceof ...)
catch_statements_1
else if (e instanceof ...)
catch_statements_2
else
throw e;
} [finally {
finally_statements
}]
关于javascript - 我可以在 Node.js 的 javascript 中使用 catch(e if e instanceof SyntaxError) 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10486043/
对于以下条件: if (a != null && a instanceof A) 或 if (a instanceof A) 首先检查 null 是否有任何优势(例如,性能方面)?两个条件的结果应该相
我正在编写一个方法,如果异常是 *someClass* 的实例,它将返回 true。但是我无法导入其中一个类,因为它在另一个模块中。我无法将该模块添加到项目中,所以我想,我不能使用 instanceo
这个问题在这里已经有了答案: The difference between "instanceof List" and 'o instanceof List" (2 个答案) 关闭 7 年前。 我知
多年来,我尽量避免使用 instanceof。在适用的情况下使用多态性或访问者模式。我想它只是在某些情况下简化了维护......还有其他需要注意的缺点吗? 但是我确实在 Java 库中到处看到它,所以
我没有看到以下任何区别: Object o = new LinkedList(); System.out.println(o instanceof List); System.
我正在像这样扩展对象: Object.prototype.is_a = function (x) { return this instanceof x; } 一切正常 "foo".is_a(Str
我在 NetBeans 中编码如下: public class Grafo { class Par { int a, b; Par(int a, int
我已经动态创建了布局。它有一些编辑文本、 TextView 、微调器等。 之后,我必须获取我介绍的关于这些 View 的信息。 所以我在做这样的事情 for(int i=0;i <= childs;i
等等!我知道还有其他非常相似的问题,但(也许是我)我需要回答其中的特定部分。 我知道可以说 Object.prototype 位于委托(delegate)链的最顶端。但是,在 Function 存在以
MooTools 有自己的instanceOf(instance, Type) 函数。 我只能假设它做了一些与 Javascript 的原生 instanceof 运算符不同的事情,但我似乎无法弄清楚
获取UTXO的方法 getUtoxs(address){ var options; if(Global.btc.network === "testnet"){ options = {
为什么在 JavaScript 中,Object instanceof Function 和 Function instanceof Object 都返回 true? 我在 Safari WebIns
为什么在 JavaScript 中 Object instanceof Function 和 Function instanceof Object 都返回 true? 我在 Safari WebIns
首先,我制作了一个“游戏渲染器”。 我的问题是,当我需要绘制当前元素时:我需要知道它是矩形、圆形还是图像等。 我的类(矩形、圆形...)是从图形扩展而来的。 public class Rectangl
想象一下,我想编写一个名为 isInstanceof 的无用方法,它返回一个 boolean。 我在想。但我不出去。 instanceof 必须像这样使用: [object] instanceof [
我有两个继承自 Player 的类:SimplePlayer 和 InterleavedPlayer。 B 类有这些方法:setPlayer(SimplePlayer player) 和 setPla
我在尝试使用以下内容时遇到了意外行为: $object instanceof $class 1/如 in the official doc. 所述,PHP 'instanceof' 关键字和命名空间可
可以在 angularjs 中使用 typeof 吗? 我有一个 ngrepeat 循环遍历我的数据,应该检查数据是字符串还是对象。 {{angular.isObject(text) &&
例如,我有 Currency 和处理 Currency 各种实现的 Exchange。我想对窗帘货币有额外的汇率,我这样做 interface Currency { double rate();} i
我有以下代码: abstract class BaseToken {} class OpenParen extends BaseToken { public static assert(t:
我是一名优秀的程序员,十分优秀!