Wednesday, 7 June 2017

Why instanceof return false?

Server.js

import Router from '@core/router/Router'

class Server {
  constructor () {
  }


  use (router) {
    if ((router instanceof Router) === false) {
      throw Error('You can only use a Router instance with Server::use')
    }

    this.router = router
  }
}

export default Server

app.js

import Server from '@core/Server/Server'
import router from '@auth/router'

var app = new Server()

app.use(router)

export default app

router.js

import Router from '@core/Router/router'

var router = new Router([
])

export default router

I get

Error: You can only use a Router instance with Server::use at Server.use (C:\Users\tom.cordelier\Desktop\chacha-emu\lib\core\Server\Server.js:89:15) at Object. (C:\Users\tom.cordelier\Desktop\chacha-emu\lib\auth\app.js:21:5) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.runMain (module.js:605:10) at run (bootstrap_node.js:427:7) at startup (bootstrap_node.js:151:9)

Look like instanceof didn't work properly, but router.constructor.name is good.

My .babelrc

{
  "presets": [
    "env",
    "stage-2",
    "stage-3"
  ],
  "plugins": [
    ["module-resolver", {
      "root": ["./src"],
      "alias": {
        "@core": "./src/core",
        "@auth": "./src/auth",
      }
    }]
  ]
}

I think i miss understand something with export default. Thanks for helping me out!



via Totomakers

No comments:

Post a Comment