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的更多相关文章
随机推荐
- Struts2中Struts.xml的作用
struts.xml 为Struts 2的核心配置文件.struts.xml文件主要负责管理应用中的Action映射,以及该Action包含的Result定义等.struts.xml中主要配置Stru ...
- js一些常用方法
string 增加 IsNullorEmpty : String.prototype.IsNullOrEmpty = function (r) { if (r === undefined || ...
- 监控memcached服务
#!/bin/bash #监控memcached服务 printf "del key\r\n" | nc 127.0.0.1 11211 &>/dev/null #使 ...
- python3+opencv+tkinter开发简单的人脸识别小程序
学校里有门图像处理的课程最终需要提交一个图像处理系统, 正好之前对于opencv有些了解,就简单的写一个人脸识别小程序吧 效果图如下 笔者IDE使用Pycharm,GUI编程直接使用内置的tkinte ...
- Docker入门实践(三) 基本操作
Docker安装完毕.我们就能够试着来执行一些命令了.看看docker能够干什么. (一) 创建一个容器 首先.让我们执行一个最简单的容器,hello-world.假设安装没有问题.并执行正确的话,应 ...
- Android 使用DrawerLayout高速实现側滑菜单
一.概述 DrawerLayout是一个能够方便的实现Android側滑菜单的组件,我近期开发的项目中也有一个側滑菜单的功能.于是DrawerLayout就派上用场了.假设你从未使用过DrawerLa ...
- Thrift 基础教程(一)安装篇
1.Thrift简单介绍 Thrift是一款由Fackbook开发的可伸缩.跨语言的服务开发框架,该框架已经开源而且增加的Apache项目.Thrift主要功能是:通过自己定义的Interface D ...
- CheckBox:屏蔽setChecked方法对OnCheckedChangeListener的影响
对于CheckBox的OnCheckedChangeListener,有两种情况下会被触发: (1)用户点击了一下CheckBox: (2)代码中调用了setChecked(boolean check ...
- 理解ThreadLocal类
1 ThreadLocal是什么 早在JDK 1.2的版本号中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路. 使用这个工具类能够 ...
- To new is C++; To malloc is C; To mix them is sin (混淆C++中的new和C中的malloc是一种犯罪)
Introduction One of the most common questions that get asked during interviews for C++ programmers i ...