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的更多相关文章
随机推荐
- 安卓开发--AsyncTask
package com.cnn.asynctask; import android.app.Activity; import android.content.Intent; import androi ...
- Ionic2中的Navigation.md
1. 概述 为了能够得到同原生应用类似的导航效果,Ionic创建了几个navagation组件来实现pages之间的导航操作,这种导航跟原生Angular2中的route机制是不一样的,我们可以借助于 ...
- 数据库Tsql语句创建--约束--插入数据
1.创建数据库 use master go if exists(select * from sysdatabases where name='数据库名字') drop database 数据库名字 g ...
- CentOS7.3 下开放防火墙的端口
CentOS 7.3默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1:关闭firewall: systemctl stop firewalld.service system ...
- python之禅---对象与元类
众所周知,python是一门面向对象的编程语言,python中一切皆对象,那么我们先探讨一下什么是对象. 一.对象 在生活中一个事物就是一个对象,比如:一只猫就是一个对象,猫的体型.猫毛的颜色等是它的 ...
- POJ——T 1986 Distance Queries
http://poj.org/problem?id=1986 Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 14383 ...
- [Python] Plotting multiple stocks
import os import pandas as pd import matplotlib.pyplot as plt def test_run(): start_date='2017-01-01 ...
- 用户向导左右滑动页面实现之ImageSwitcher
当第一次打开一个app时,通常有一个使用向导介绍本APK的基本功能和用法,这个向导是很重要的,方便用户能高速知道和适应该app如何用. 实现此使用向导有非常多种方法,比方用ImageSwitcher, ...
- 深入理解maven及应用(一):生命周期和插件
在项目里用了快一年的maven了,近期突然发现maven项目在eclipse中build时很慢,由于经经常使用clean install命令来build项目,也没有管那么多,但近期实在受不了乌龟一样的 ...
- Linux学习笔记--cp命令(复制)
cp:英文名copy,复制的意思. 1. 命令格式: cp [选项] 源文件或文件夹 目标文件或文件夹 cp [选项] 源文件1 源文件2 源文件3 ... 目标文件夹 2. 经常使用选项: &quo ...