CNode

nodejs 里 Type tags 指的是什么?

问答
Yyyp544784013发布于8 年前最后回复8 年前3 回复3628 浏览0 收藏

nodejs 这个接口里有句话不是明白,请大神解惑。 assert.deepStrictEqual(actual, expected[, message]) 这里有句话说:

Type tags of objects should be the same.

那问题来了,Type tags 是什么意思? 它文档里举了个例子, 说这2个对象不一样,是因为 type tags 不一样:

const date = new Date();
const fakeDate = {};
Object.setPrototypeOf(fakeDate, Date.prototype);

// Different type tags:
assert.deepStrictEqual(date, fakeDate);
// AssertionError: Input A expected to strictly deep-equal input B:
// + expected - actual
// - 2018-04-26T00:49:08.604Z
// + Date {}

我理解的 type tagstypeof date 返回的值,但是 typeof datetypeof fakeDate 结果都是 object ,所以我不明白 type tags 指的是什么?

查看回复

回复 (3)

C
chenzeZzz#1·8 年前

let obj1 = {}; let obj2 = new Date();

typeof obj1; // 'object' typeof obj1; // 'object'

obj1 instanceof Date; //false obj2 instanceof Date; //true

M
miserylee#2·8 年前

https://stackoverflow.com/questions/50305807/whats-the-meaning-of-type-tags-in-nodejs

这个可能也是题主问的吧?底下的回答就挺好的 :)

Y
yyp544784013#3·8 年前
引用 miseryleehttps://stackoverflow.com/questions/50305807/whats the meaning of type tags in nodejs 这个可能也是题主问的...

@miserylee 确实是我问的,但是没讲清啊 不管你是 用 typeof 还是 Object.getPrototypeOf 得出的结果都是一样的。

参与回复
登录后即可参与回复。登录