node.js - How to use javascript export keyword in browser or console - Stack Overflow

export keyword is introduced in ecmascript5:var myFunc1 = function() { console.log('hello');

export keyword is introduced in ecmascript5:

var myFunc1 = function() { console.log('hello'); };   
export.myFunc1 = myFunc1;

If I run above code in firefox console it gives error:

SyntaxError: missing declaration after 'export' keyword  
export.myFunc1 = myFunc1;

I don't understand what I need to declare.

Am I using it in the wrong way?

Any advice would be nice!

export keyword is introduced in ecmascript5:

var myFunc1 = function() { console.log('hello'); };   
export.myFunc1 = myFunc1;

If I run above code in firefox console it gives error:

SyntaxError: missing declaration after 'export' keyword  
export.myFunc1 = myFunc1;

I don't understand what I need to declare.

Am I using it in the wrong way?

Any advice would be nice!

Share Improve this question edited May 9, 2015 at 14:57 Mast 1,9045 gold badges33 silver badges48 bronze badges asked May 9, 2015 at 14:38 vijayvijay 11.1k12 gold badges66 silver badges81 bronze badges 2
  • 1 What did you expect that code to do? Where did you learn that the export keyword is used that way? The w3schools page you link to only says that it's reserved in ES5, nothing else. – JJJ Commented May 9, 2015 at 14:43
  • 1: i expect to know what that keyword does in javascript and how to use it in any way also kept nodejs exports with s keyword in mind and tried the above code in browser – vijay Commented May 9, 2015 at 15:12
Add a ment  | 

2 Answers 2

Reset to default 5

The syntax for ES6 export looks like this:

//------ lib.js ------
export const sqrt = Math.sqrt;
export function square(x) {
    return x * x;
}
export function diag(x, y) {
    return sqrt(square(x) + square(y));
}

//------ main.js ------
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5

Note that this is different from the CommonJS modules.export syntax used in Node.js.

Node js uses exports to expose functionality in modules to their implementers

defined here. https://nodejs/api/modules.html#modules_module_exports

Is this what you're trying to do?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211553a4616871.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信