小编abh*_*ekp的帖子

使用ES6类的instanceof继承链不起作用

使用ES6 class语法,我想知道为什么instanceof当有多个继承链时,运算符不适用于继承链?

(可选阅读)

instanceof操作员如何工作?

obj instanceof Constructor,instanceof操作员检查函数的'prototype'属性Constructor是否存在于原型链中obj.如果它存在,请返回true.否则,false.


在下面的代码片段中,BTError继承自Error(1.)并SomeErrorBTError(3.)扩展.
但是,正如我们可以看到从(4),该instanceof操作结果falsenew SomeError() instanceof BTError它在我的理解应该是true.

class BTError extends Error {}
console.log('1.', Reflect.getPrototypeOf(BTError.prototype) === Error.prototype); // 1. true
console.log('2.', new BTError() instanceof Error); // 2. true

console.log('');

class SomeError extends BTError {} …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance class ecmascript-6 es6-class

10
推荐指数
2
解决办法
4280
查看次数

MongoError:E11000 唯一复合索引的重复键错误集合

unique compound与其他unique只有索引的此类问题不同,问题与索引有关。我也有sparse: true索引。

我的收藏中有以下索引

[
  {
    "v": 2,
    "key": {
      "_id": 1
    },
    "name": "_id_",
    "ns": "somedb.votes"
  },
  {
    "v": 2,
    "key": {
      "answerId": 1
    },
    "name": "answerId_1",
    "ns": "somedb.votes",
    "sparse": true,
    "background": true
  },
  {
    "v": 2,
    "key": {
      "questionId": 1
    },
    "name": "questionId_1",
    "ns": "somedb.votes",
    "sparse": true,
    "background": true
  },
  {
    "v": 2,
    "unique": true,
    "key": {
      "answerId": 1,
      "votedBy": 1
    },
    "name": "answerId_1_votedBy_1",
    "ns": "somedb.votes",
    "sparse": true,
    "background": true
  },
  {
    "v": …
Run Code Online (Sandbox Code Playgroud)

indexing mongodb compound-index

5
推荐指数
1
解决办法
2万
查看次数

在Javascript中定义对象方法的两种方法有什么区别?

在阅读Eric Elliot 撰写的这篇文章https://medium.com/javascript-scene/the-single-biggest-mistake-programmers-make-every-day-62366b432308时,我遇到了以下类型的对象方法定义.

var obj = {
  getX() {
    document.write('X');
  }
}

obj.getX(); // X
Run Code Online (Sandbox Code Playgroud)

它与以下类型的定义有何不同?

var obj = {
  getX: function getX() {
    document.write('X');
  }
}

obj.getX(); // X
Run Code Online (Sandbox Code Playgroud)

javascript function object

1
推荐指数
1
解决办法
52
查看次数