es69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>交换变量的值</title>
<script src="../../../vendor/traceur.js"></script>
<script src="../../../vendor/bootstrap.js"></script>
<script type="text/traceur">
//ES5
console.log("ES5:");
var a = 100;
var b = 200;
console.log("交换前:");
console.log("a = " + a); //a = 100
console.log("b = " + b); //b = 200
var temp;
temp = a;
a = b;
b = temp;
console.log("交换后:");
console.log("a = " + a); //a = 200
console.log("b = " + b); //b = 100 //ES6用于大型项目开发节约内存
console.log("ES6:");
var x = 100;
var y = 200;
console.log("交换前:");
console.log("x = " + x); //x = 100
console.log("y = " + y); //y = 200
[x, y] = [y, x];//[x, y] = [200, 100];
console.log("交换后:");
console.log("x = " + x); //x = 200
console.log("y = " + y); //y = 100
---------------------------------------------
function fun () {
return [1, 2, 3];
}; var [x, y, z] = fun();//函数返回多个值,并且可以只要返回的哪个值
console.log(x); //1
console.log(y); //2
console.log(z); //3
----------------------------------------------
function fun () {
return {
id : "007",
name: "Conan",
age : 28
};
};
var { id, name, age } = fun();
console.log(id); //007
console.log(name); //Conan
console.log(age); //28
var { id: person_id, name: person_name, age: person_age } = fun();
console.log(person_id); //007
console.log(person_name); //Conan
console.log(person_age); //28
--------------------------------------------
// 参数是一组有次序的值
function fun ([x, y, z]) {
//x = 100;
//y = 200;
//z = 300;
};
fun([100, 200, 300]); // 参数是一组无次序的值
function fun ({id, age,name}) {
//id = "007";
console.log(name);
//age = 28;
};
fun({id: "007", name: "Conan", age: 28});
---------------------------------------------
var jsonData = {
id: "007",
name: "Conan",
age: 28,
score: {
Chinese: 98,
Math: 148,
English: 107
}
};
console.log(jsonData); console.log("ES5:");
console.log("Person's Number is:" + jsonData.id);
console.log("Person's Name is:" + jsonData.name);
console.log("Person's age is:" + jsonData.age);
console.log("Person's Chinese score is:" + jsonData.score.Chinese);
console.log("Person's Math score is:" + jsonData.score.Math);
console.log("Person's English score is:" + jsonData.score.English); console.log("ES6:");
let { id: number, name, age, score: score } = jsonData;
console.log("Person's Number is:" + number);
console.log("Person's Name is:" + name);
console.log("Person's age is:" + age);
console.log("Person's Chinese score is:" + score.Chinese);
console.log("Person's Math score is:" + score.Math);
console.log("Person's English score is:" + score.English);
----------------------------------------------- </script>
</head>
<body> </body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>遍历Map结构</title>
<script src="../../../vendor/traceur.js"></script>
<script src="../../../vendor/bootstrap.js"></script>
<script type="text/traceur">
var map = new Map();
map.set("id", "007");
map.set("name", "Conan"); console.log(map);//Map(2) {"id" => "007", "name" => "Conan"}
console.log(typeof(map));//object // 获取键名和键值
for (let [key, value] of map) {
console.log(key + " is " + value);
};
// id is 007
// name is Conan // 获取键名
for (let [key] of map) {
console.log(key);
};
// id
// name for (let [, value] of map) {
console.log(value);
};
// 007
// Conan
</script>
</head>
<body> </body>
</html>
es69的更多相关文章
随机推荐
- CURRENMONTH TAG in Automation Framework
/** * @param input * <CURRENTMONTH><CURRENTMONTH+1> * @return Month "MM" */ pr ...
- 安装Git和图形化软件[SouceTree跳过首次登陆]
安装Git和图形化软件[SouceTree跳过首次登陆] 标签(空格分隔): 版本控制 安装GIT[客户端]: 下载:[https://git-scm.com/downloads/] 安装:[next ...
- kali 2.0 linux中的Nmap的操作系统扫描功能
不多说,直接上干货! 可以使用-O选项,让Nmap对目标的操作系统进行识别. msf > nmap -O 202.193.58.13 [*] exec: nmap -O 202.193.58.1 ...
- PostgreSQL Replication之第四章 设置异步复制(2)
4.2 配置级联复制 正如您在本章已经看到的,设置流复制真的很容易.只需要设置几个参数,做一个基础备份,并享受您的复制设置. 在许多情况下,这种情况更有一点点微妙.在这个例子中我们假设:我们要使用一个 ...
- studyLink
http://order.csdn.net/myorder/detail?id=850343 csdn
- 使用物化视图解决GoldenGate不能使用中文表名问题
源端: conn sh/sh create table "学生" ("学号" number primary key,"姓名" varchar ...
- 如何知道 CPU 是否支持虚拟化技术(VT)
作者: Sk 译者: LCTT geekpi 我们已经知道如何检查你的 Linux 操作系统是 32 位还是 64 位以及如何知道你的 Linux 系统是物理机还是虚拟机.今天,我们将学习另一个有用的 ...
- bzoj1051 [HAOI2006]受欢迎的牛 tarjan&&缩点
题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所有奶 牛都是自恋狂,每头奶牛总是喜欢自己的.奶牛之间的“喜欢”是可以传递的——如果A喜 欢B,B喜欢C,那么A也喜欢C ...
- HDU-2045 不容易系列之(3)—— LELE的RPG难题 找规律&递推
题目链接:https://cn.vjudge.net/problem/HDU-2045 找规律 代码 #include <cstdio> long long num[51][2]; int ...
- CF718C Sasha and Array(线段树维护矩阵)
题解 (不会矩阵加速的先去学矩阵加速) 反正我想不到线段树维护矩阵.我太菜了. 我们在线段树上维护一个区间的斐波那契的列矩阵的和. 然后询问时提取每个符合题意列矩阵的答案项(不是列矩阵存了两项吗,一个 ...