This problem in import xxx from xxx and const xxx = require('xxx')

I saw a piece of code by chance, which probably means the following
// 2.js

this.a = this.a || {
    
    };
this.a.b = {
    
    
  "name": "Eric"
}
this.c = {
    
    
  "age": "20"
}
this.d = {
    
    
  "hobby": "ball"
}
// 1.js

const abc = require('./2.js');

console.log(abc);
// 打印结果:
// {
    
    
      a: {
    
     b: {
    
     name: 'Eric' } },
      c: {
    
     age: '20' }, 
      d: {
    
     hobby: 'ball' } 
   }

In 2.js, only a few variables are defined and not exported. Then import it in 1.js.

According to the result, this in 2.js points to the variable abc that receives require;

It has been verified that import xxx from xxx has the same result.

Guess you like

Origin blog.csdn.net/mochenangel/article/details/118579423