es67
<!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">
// ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring) 。
// ES5
var a = 1;
var b = 2;
var c = 3; // ES6
var [a, b, c] = [1, 2, 3];
console.log(a); //1
console.log(b); //2
console.log(c); //3 --------------------------------------------------------
let [foo, [[bar], base]] = [1, [[2], 3]];
console.log(foo); //1
console.log(bar); //2
console.log(base); //3 let [, , third] = ["first", "second", "third"];
console.log(third); //third let [one, , three] = ["One", "Two", "Three"];
console.log(one); //One
console.log(three); //Three let [head, ...tail] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(head); //0
console.log(tail); //[1, 2, 3, 4, 5, 6, 7, 8, 9] let [head, tail] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(head); //0
console.log(tail); //1
----------------------------------------------------
var [temp] = [];
console.log(temp); //undefined
var [first, second] = [100];
console.log(first); //100
console.log(second);//undefined ---------------------------------------------------- let [x, y] = [1, 2, 3];
console.log(x); //1
console.log(y); //2 let [a, [b], c] = [1, [2, 3], 4];
console.log(a); //1
console.log(b); //2
console.log(c); //4 -----------------------------------------------
var [temp = "string"] = [];
console.log(temp); //string,没有值走默认 var [temp = "string"] = ["tempString"];
console.log(temp); //tempString,默认值和指定值冲突(指定值不为未定义)用指定值、指定值为未定义用默认值, var [x = "aaa", y] = ["bbb"];
console.log(x); //bbb
console.log(y); //undefined var [m, n = "aaa"] = ["bbb"];
console.log(m); //bbb
console.log(n); //aaa var [p, q = "aaa"] = ["bbb", undefined];
console.log(p); //bbb
console.log(q); //aaa -------------------------------------------------------
var [temp] = 1; //正确写法:var [temp] = [1]; 报错1[Symbol.iterator] is not a function at eval
var [temp] = false; //报错:false[Symbol.iterator] is not a function at eval
var [temp] = NaN; //报错:NaN[Symbol.iterator] is not a function at eval
var [temp] = undefined; //报错:Cannot read property 'Symbol(Symbol.iterator)' of undefined at eval
var [temp] = null; //报错:Cannot read property 'Symbol(Symbol.iterator)' of null at eval
------------------------------------------------------- </script>
</head>
<body> </body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Iterator接口</title>
<script src="../../../vendor/traceur.js"></script>
<script src="../../../vendor/bootstrap.js"></script>
<script type="text/traceur">
//只要某种数据结构具有Iterator接口,都可以采用数组形式的解构赋值。
let [a, b, c] = new Set(["a", "b", "c"]);
console.log(a); //a
console.log(b); //b
console.log(c); //c function* fibs() {
let a = 0;
let b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
};
var [first, second, third, fourth, fifth, sixth] = fibs();
console.log(sixth); //5
</script>
</head>
<body> </body>
</html>
es67的更多相关文章
- 简述WebService的使用(一)
环境: vs版本:vs2013 windows版本:win7 IIS版本:IIS7.0 (如果觉得对您有用,请点击右下角[推荐]一下,让更多人看到,谢谢) 配置环境: 主要针对于IIS ·首先,有很多 ...
- vue源码入口文件分析
开发vue项目有段时间了, 之前用angularjs 后来用 reactjs 但是那时候一直没有时间把自己看源码的思考记录下来,现在我不想再浪费这 来之不易的思考, 我要坚持!! 看源码我个人感觉非常 ...
- 开始在web中使用JS Modules
本文由云+社区发表 作者: 原文:<Using JavaScript modules on the web> https://developers.google.com/web/funda ...
- create-react-app入门教程
Create React App是FaceBook的React团队官方出的一个构建React单页面应用的脚手架工具.它本身集成了Webpack,并配置了一系列内置的loader和默认的npm的脚本,可 ...
- Angular 快速入门
Angular 快速入门 AngularJS 官方网址 Angular:https://www.angular.cn/ Angular官网:https://angularjs.org/ Angular ...
- vue koa2 mongodb 从零开始做个人博客(一) 登录注册功能前端部分
0.效果演示 插入视频插不进来,就很烦.可以出门右拐去优酷看下(点我!). 1.准备工作 1.1前端框架 前端使用了基于vue.js的nuxt.js.为什么使用nuxt.js? 首先我做的是博客的项目 ...
随机推荐
- 33.AngularJS 应用 angular.module定义应用 angular.controller控制应用
转自:https://www.cnblogs.com/best/tag/Angular/ AngularJS 模块(Module) 定义了 AngularJS 应用. AngularJS 控制器(Co ...
- Why functions - Not only for python
It may not be clear why it is worth the trouble to divide a program into functions. There are a lot ...
- 12.C语言控制窗口
void main() { //创建一个窗口编号变量,寻找QQ的窗口 HWND win = FindWindowA("TXGuiFoundation", "QQ" ...
- BMP图片格式模型
BMP BMP(全称Bitmap)是Window操作系统中的标准图像文件格式 可以分成两类:设备相关位图(DDB)和设备无关位图(DIB),使用非常广. 它采用位映射存储格式,除了图像深度可选以外,不 ...
- POJ 3280 DP
题意: 思路: DP f[i][j]表示把i到j变成回文串的最少代价 f[start][end]=f[start+1][end]+min(node[a[start]].del,node[a[start ...
- Metasploit的攻击实例讲解----辅助扫描工具
不多说,直接上干货! 怎么弹出来这个呢,连续按两次tab. msf > use auxiliary/scanner/ Display all possibilities? (y or n) us ...
- BZOJ 2127: happiness(最小割解决集合划分)
Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 2350 Solved: 1138[Submit][Status][Discuss] Descript ...
- windows, fast-rcnn CPU版本的安装配置
一:安装准备 1:caffe的安装配置,本人用的是happynear大神的caffe版本,具体链接https://github.com/happynear/caffe-windows,编译时需要用到p ...
- [Poi] Build and Analyze Your JavaScript Bundles with Poi
Ever wonder where those extra KB in your bundle are coming from? This lesson walks you through runni ...
- 第五章,AsyncTask和ProgressBar的练习(Android)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...