3

I'm using the angular webpack starter: https://github.com/AngularClass/angular-starter

and had noticed that in the angular docs, they are exporting an animation as a const. If import the animation in two components and use it, do I have two instances or one in the global scope?

import { animation } from /file

How do the imports work?

Jonathan002
  • 9,639
  • 8
  • 37
  • 58
  • 4
    Importing doesn't create instances, therefore you only have one. – Günter Zöchbauer Jul 24 '17 at 12:42
  • 1
    Possible duplicate of [In the \`import\` syntax of ES6, how is a module evaluated exactly?](https://stackoverflow.com/questions/36564901/in-the-import-syntax-of-es6-how-is-a-module-evaluated-exactly) – Estus Flask Jul 24 '17 at 13:58

1 Answers1

3

do I have two instances or one in the global scope

All modules are evaluated only once on first import. So a single instance of a module => single instance of exported members.

basarat
  • 261,912
  • 58
  • 460
  • 511