遗留模式


稳定性: 0 - 废弃: 改为使用严格模式。

当直接访问 assert 而不是使用 strict 属性时,将对名称中没有 "strict" 的任何函数(例如 assert.deepEqual())使用抽象的相等性比较

它可以使用以下方式访问:

const assert = require('assert');

建议使用严格模式,因为抽象的相等性比较通常会产生意外的结果。 特别是对于 assert.deepEqual(),其中的比较规则是松散的:

// 注意:这不会抛出 AssertionError!
assert.deepEqual(/a/gi, new Date());

Stability: 0 - Deprecated: Use strict mode instead.

When accessing assert directly instead of using the strict property, the Abstract Equality Comparison will be used for any function without "strict" in its name, such as assert.deepEqual().

It can be accessed using:

const assert = require('assert');

It is recommended to use the strict mode instead as the Abstract Equality Comparison can often have surprising results. This is especially true for assert.deepEqual(), where the comparison rules are lax:

// WARNING: This does not throw an AssertionError!
assert.deepEqual(/a/gi, new Date());