ES6基础

This commit is contained in:
罗祥
2019-12-16 16:31:44 +08:00
parent 0b506230fe
commit 085632c43f
5 changed files with 208 additions and 6 deletions

View File

@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script type="module" src="index.js"></script>
</head>
<body>
INDEX!
</body>
</html>

View File

@ -0,0 +1,10 @@
import {multiply} from "./module.js";
let result = multiply(2, 2);
alert(result);
var RegExp = "Hello!";
console.log(window.RegExp); // 在模块顶级作用域中创建的变量,不会被自动添加到共享的全局作用域,它们只会在模块顶级作用域内部存在
console.log(this); // 模块顶级作用域的 `this` 值为 undefined
console.log(window.RegExp === RegExp);

View File

@ -0,0 +1,24 @@
// 1.导出变量或常量
export var color = "red";
export let name = "Nicholas";
export const magicNumber = 7;
// 2.导出函数
export function sum(num1, num2) {
return num1 + num1;
}
// 3.导出类
export class Rectangle {
constructor(length, width) {
this.length = length;
this.width = width;
}
}
function multiply(num1, num2) {
return num1 * num2;
}
// 4.导出已有的函数
export {multiply};