Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

为什么import导入的对象,可以用counter++,不能用counter+=1

早上看了个题目,不懂为什么会这样

//a.js
let counter = 10;
export default counter;

// index.js
import counter from "./a";
counter ++//这个是可以打印出11
counter+=1//error,counter is not defined
console.log(counter);

(下午17:00)补充下环境,用webpack起的dev-server服务:

webpack  4.41.2
nodejs  v14.7.0
webpack-dev-server  3.9.0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我想问,这个counter不是只读的吗,你改变它的值没有报错吗
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...