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的更多相关文章
随机推荐
- Leaflet学习笔记(一)
一.简介 Leaflet是一个主要适用于移动端交互地图的领先的开源javascript库.虽然js库只有38KB左右,但是却能满足大部分开发者的所有功能需求. Leaflet拥有着简单,高效和实用的设 ...
- HD-ACM算法专攻系列(2)——Rightmost Digit
题目描述: 源码: /**/ #include"iostream" using namespace std; int main() { int t, mod; long long ...
- windows, fast-rcnn CPU版本的安装配置
一:安装准备 1:caffe的安装配置,本人用的是happynear大神的caffe版本,具体链接https://github.com/happynear/caffe-windows,编译时需要用到p ...
- EasyUI 之 DataGrid的两种赋值方法
方法一:使用ViewData赋值 首先,我们创建一个User的实体类 public class User { public string UserID; public string UserName; ...
- js对浏览器产生的影响
Js 是单线程执行引擎.在我们动态修改一些属性时会产生两种效果: 1.Repaint ----- 一部分重画,修改 div 的颜色呀,但是尺寸没有改变. 2.Reflow ---- 元素 ...
- php实现自动加载类
PHP 实现自动加载类:
- 03016_DBCP连接池
1.连接池概述 (1)用池来管理Connection,这样可以重复使用Connection: (2)有了池,所以我们就不用自己来创建Connection,而是通过池来获取Connection对象: ( ...
- Maven学习总结(21)——Maven常用的几个核心概念
在使用Maven的过程中,经常会遇到几个核心的概念,准确的理解这些概念将会有莫大的帮助. 1. POM(Project Object Model)项目对象模型 POM 与 Java 代码实现了解耦,当 ...
- 洛谷 P3663 [USACO17FEB]Why Did the Cow Cross the Road III S
P3663 [USACO17FEB]Why Did the Cow Cross the Road III S 题目描述 Why did the cow cross the road? Well, on ...
- 绿色版SecureCRT启动崩溃,遇到一个致命的错误且必须关闭
百度搜了半天,大家都是说删除注册表的VanDyke就能解决问题,但是我用的是绿色版的,删除VanDyke后还不行. 然后试了一下重新解压出一个绿色版的SecureCRT,发现能用. 但之前我配置了很多 ...