自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

JavaScript6里都有啥新鮮東西?

開發(fā) 前端
JavaScript 6里都有啥新鮮東西?讓我們一起來看看JavaScript 6的一些新特性。

JavaScript 6里都有啥新鮮東西?讓我們一起來看看JavaScript 6的一些新特性。

letconst (用來定義block-local變量), 程序過程中的function

解構(gòu): let {x, y} = pt; let [s, v, o] = triple();
(前提是let pt = {x:2, y:-5})

缺省參數(shù)值: function f(x, y=1, z=0) {…}

其它參數(shù): function g(i, j, ...r) { return r.slice(i, j); }
(不需要再使用 arguments )。

數(shù)據(jù)展開: let a = [0,1,2,3], o = new Something(...a);。也可以用于數(shù)組字面量: [1, ...array, 4].

對象簡寫:
let one = 1; { one, func_one() {return 1;}, ['key ' + one]: 1 }.

函數(shù)簡寫 (a) => a * a 效果等同
(function(a) { return a * a; }).bind(this)

map, set: let m = new Map(); m.set(key, value); m.has(key); m.get(key).
還包括 .clear().delete().forEach().keys().

弱map: let map = new WeakMap()。當(dāng)有循環(huán)引用時使用它。同理new WeakSet()

promise: new Promise((resolve, reject) => {…}).

當(dāng) promise.then(value => {…})時,resolve(valueOrPromise) 返回承諾的值 (或者是一個新的promise,形成鏈式調(diào)用)

當(dāng)promise.then(…).then(…).catch(error => {…})reject(new Error(…))中斷promise

快速 promise 創(chuàng)建: Promise.resolve(value)Promise.reject(error).

迭代: Promise.all(listOfPromises).then(listOfValues => …),
Promise.race(listOfPromises).then(valueThatResolvedFirst => …)

代理: let obj = new Proxy(proto, handler).
簡單說: 使用類對象的元素進行重載(能夠帶來所有可訪問的屬性。)

生成器: function* gen() { yield 1; yield 2; }
事實上,gen() 會返回一個含有 next() 函數(shù)的對象。

循環(huán): for (var [key, val] of items(x)) { alert(key + ',' + val); }

類定義中使用extendssuper, 和 static:

  1. class Point extends Base { 
  2.   constructor(x,y) { 
  3.     super(); 
  4.     this[px] = x, this[py] = y; 
  5.     this.r = function() { return Math.sqrt(x*x + y*y); } 
  6.   } 
  7.   get x() { return this[px]; } 
  8.   get y() { return this[py]; } 
  9.   proto_r() { return Math.sqrt(this[px] * this[px] + 
  10.       this[py] * this[py]); } 
  11.   equals(p) { return this[px] === p[px] && 
  12.       this[py] === p[py]; } 

符號(Symbol)對象,創(chuàng)建私有的key,可用于map和類中(私有成員
members)。

  1. let a = Map(); 
  2.   let k = Symbol(); 
  3.   a.set(k, 'value'); 
  4.   // 這里你可以訪問和設(shè)置'value',比如a.get(k)。 
  5. //這里不行,k是不可見的。 

模塊化:

  1. module math { 
  2.   export function sum(x, y) { 
  3.     return x + y; 
  4.   } 
  5.   export var pi = 3.141593; 
  6.  
  7. import {sum, pi} from math; 
  8. alert(sum(pi,pi)); 

模板式字符串: 可以多行,并能嵌入變量。
`You are ${age} years old.`.

  1. // 多行字符串 
  2. re`line1: (words )* 
  3. line2: \w+` 
  4.  
  5. // It desugars to: 
  6. re({raw:'line1: (words )*\nline2: \w+'
  7.     cooked:'line1: (words )*\nline2: \w+'}) 

類型化數(shù)組

語言規(guī)范: http://people.mozilla.org/~jorendorff/es6-draft.html

語言規(guī)格建議書: http://wiki.ecmascript.org/doku.php?id=harmony:proposals

 

責(zé)任編輯:張偉 來源: webhek
相關(guān)推薦

2018-06-22 15:47:06

數(shù)據(jù)庫PostgreSQLMySQL

2011-12-08 08:58:28

JavaScript

2024-07-12 15:08:23

Python@wraps函數(shù)

2015-12-01 09:34:15

電燈無限速度網(wǎng)速

2015-07-13 11:20:38

2020-12-21 17:55:02

華為HarmonyOS鴻蒙

2012-01-11 15:30:11

2019-07-15 08:22:43

JavaScript開源GitHub

2022-05-26 09:29:20

微軟Edge瀏覽器

2011-06-09 16:08:37

投影機體驗

2011-03-30 09:58:54

IPv6過度IPv4

2019-11-18 17:01:13

程序員技術(shù)跳槽那些事兒

2017-06-09 06:59:06

Tomcat特權(quán)應(yīng)用容器

2011-08-12 10:11:37

智慧運算IBMpower7

2021-06-27 06:28:55

微信微信派微信官網(wǎng)改版

2023-11-03 07:32:07

數(shù)據(jù)庫產(chǎn)品文檔結(jié)構(gòu)

2011-06-07 09:22:43

jQueryjQuery插件

2018-03-08 10:24:48

Redis運維 RDR

2021-07-05 16:10:35

JavaScript代碼前端

2017-02-09 18:19:54

點贊
收藏

51CTO技術(shù)棧公眾號