首页 > 其他 > 详细

ES6之导入模块时的内存共享

时间:2018-05-29 18:27:02      阅读:199      评论:0      收藏:0      [点我收藏+]

项目结构

技术分享图片

主页面

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>测试</title>
        <script type="module" src="index.js"></script>
    </head>
    <body>
        
    </body>
</html>

index.js脚本

import {cruiser} from ‘./toyato.js‘;
import {discovery} from ‘./land-rover.js‘;
import {tire} from ‘./tire.js‘;

console.log(`轮胎使用厂家数量: ${tire.count}`);

toyato.js

import {tire} from ‘./tire.js‘;

tire.count++;

export let cruiser = {
    name : ‘Land Cruiser‘
};

land-rover.js

import {tire} from ‘./tire.js‘;

tire.count++;

export let discovery = {
    name : ‘Land Rover Discovery‘
};

tire.js

// 导出一个轮胎对象

export let tire = {
    name : ‘BRIDGESTONE‘,
    count : 0
};

运行结果

技术分享图片

 

ES6之导入模块时的内存共享

原文:https://www.cnblogs.com/sea-breeze/p/9106241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!