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的更多相关文章
随机推荐
- matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
Customizing plots with style sheets - Matplotlib 1.5.1 documentation 1. 使用和显示其他画布风格 >> import ...
- rails 开发随手记 7
jQuery 1.9 中如何修改选择项 $("select option:contains(teacher5)").prop('selected', 'selected'); 效果 ...
- 《剑指offer》合并两个排序的链表
一.题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 二.输入描述 两个递增排序的链表 三.输出描述 合并成一个递增排序的链表 四.牛客网提供的框 ...
- Busy waiting
In computer systems organization or operating systems, "busy waiting" refers to a process ...
- JTable表格案例
package com.szht.gpy.frame; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import ...
- SSD-tensorflow-1 demo
一.简易识别 用最简单的已训练好的模型对20类目标做检测. 你电脑的tensorflow + CUDA + CUDNN环境都是OK的, 同时python需要安装cv2库 { 'aeropla ...
- bzoj2100 [Usaco2010 DEC]Apple Delivery苹果贸易
题目描述 一张P个点的无向图,C条正权路.CLJ要从Pb点(家)出发,既要去Pa1点NOI赛场拿金牌,也要去Pa2点CMO赛场拿金牌.(途中不必回家)可以先去NOI,也可以先去CMO.当然神犇CLJ肯 ...
- ubuntu 安装Gremlin 的图形化环境
参考文档:https://www.jianshu.com/p/618cf6667381 部署HugeGraphServer # 直接下载release包 网址:https://github.com/h ...
- Vuex-一个专为 Vue.js 应用程序开发的状态管理模式
为什么会出现Vuex 非父子关系的组件如何进行通信?(Event Bus)bus.js import Vue from 'vue'; export default new Vue(); foo.vue ...
- Java基础学习总结(17)——线程
一.线程的基本概念 线程理解:线程是一个程序里面不同的执行路径 每一个分支都叫做一个线程,main()叫做主分支,也叫主线程. 程只是一个静态的概念,机器上的一个.class文件,机器上的一个.exe ...