Code Monkey home page Code Monkey logo

Comments (3)

ckinmind avatar ckinmind commented on August 26, 2024
  1. import 和export 是ES6中的模块化方案,详情参考阮一峰的ES6教程中关于模块的部分ECMAScript 6 入门: Module

  2. 我有尝试过直接在浏览器环境下import一个js文件,结果是报错SyntaxError: Unexpected token import, 这个需要在node环境里使用babel工具将其转化为ES5代码,这个可以在babel官网体验babel官网
    这里做了一个测试

// 使用ES6的import写法
import {sex,echo} from "./a.js"
console.log(sex)   // boy
echo(sex) // boy

//经过babel转变之后
"use strict";

var _a = require("./a.js");

console.log(_a.sex); // boy
(0, _a.echo)(_a.sex); // boy

from reactcollect.

ckinmind avatar ckinmind commented on August 26, 2024
  1. require是node遵循ommonJS模块规范,内置的命名,用来加载模块文件

  2. require命令的基本功能是,读入并执行一个JavaScript文件,然后返回该模块的exports对象。如果没有发现指定模块,会报错

  3. 更多参考阮一峰的node教程CommonJS规范/Module

from reactcollect.

ckinmind avatar ckinmind commented on August 26, 2024

更多资料:
通过 Babel 使用 ES6 的 import
javascript | es6 一个关于import的语法问题
ES6模块的import和export用法总结

from reactcollect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.