<分区>
This is not a duplicate of below questions which is dealing with browser specific questions. I'm expecting an answer whether
import / export
will work in Client side or not.
- ECMA 6 Not working although experimental js is enabled
- how export variable in ES6 in Chrome/Firefox?
//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
"use strict";
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Import Check</title>
</head>
<body>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
Error that I'm getting in Chrome:
Tested Browser: Google Chrome Version 47.0.2526.106
- 是否可以使代码在任何浏览器中工作或不工作?
- 比方说,我们选择了一个转译器 (
BabelJS
) 并转译了代码。import
/export
文件代码片段将在客户端或服务器端工作(在节点服务器中作为 require 方法)?