导入并使用es6调用函数 [英] import and call a function with es6

查看:477
本文介绍了导入并使用es6调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前:

var debug = require('debug')('http')
  , http = require('http')
  , name = 'My App';

使用es6,如何像第一行那样立即导入和调用?

With es6, how can I import and invoke right away like the first line?

import debug from 'debug'();

是否否?

推荐答案

您需要两行:

import debugModule from 'debug';
const debug = debugModule('http');

导入语法是声明式导入语法,它不执行任何函数。

The import syntax is a declarative import syntax, it does not execute any functions.

这篇关于导入并使用es6调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆