mac原生支持ntfs缺点的是 ES5 还是 ES6

距离发布已有半年,对于ES6和ES5,你了解多少?这篇文章讲了,ES5,ES6的一些介绍和区别,挺详细的,结尾附录:?
以下来自:
什么是JavaScript
JavaScript一种动态类型、弱类型、基于原型的客户端脚本语言,用来给网页增加动态功能。(好吧,概念什么最讨厌了)
在运行时确定数据类型。变量使用之前不需要类型声明,通常变量的类型是被赋值的那个值的类型。
计算时可以不同类型之间对使用者透明地隐式转换,即使类型不正确,也能通过隐式转换来得到正确的类型。
新对象继承对象(作为模版),将自身的属性共享给新对象,模版对象称为原型。这样新对象实例化后不但可以享有自己创建时和运行时定义的属性,而且可以享有原型对象的属性。
PS:新对象指函数,模版对象是实例对象,实例对象是不能继承原型的,函数才可以的。
JavaScript由三部分组成:
1. ECMAScript(核心)
作为核心,它规定了语言的组成部分:语法、类型、语句、关键字、保留字、操作符、对象
PS:*不完全兼容的实现
2. DOM(文档对象模型)
DOM把整个页面映射为一个多层节点结果,开发人员可借助DOM提供的API,轻松地删除、添加、替换或修改任何节点。
PS:DOM也有级别,分为DOM1、DOM2、DOM3,拓展不少规范和新接口。
3. BOM (浏览器对象模型)
支持可以访问和操作浏览器窗口的浏览器对象模型,开发人员可以控制浏览器显示的页面以外的部分。
PS:BOM未形成规范
作为ECMAScript第五个版本(第四版因为过于复杂废弃了),浏览器支持情况可看第一副图,增加特性如下。
1. strict模式
严格模式,限制一些用法,'use&strict';
2.&Array增加方法
增加了every、some&、forEach、filter&、indexOf、lastIndexOf、isArray、map、reduce、reduceRight方法
PS: 还有其他方法&Function.prototype.bind、String.prototype.trim、Date.now
3.&Object方法
Object.getPrototypeOf
Object.create
Object.getOwnPropertyNames
Object.defineProperty
Object.getOwnPropertyDescriptor
Object.defineProperties
Object.keys
Object.preventExtensions / Object.isExtensible
Object.seal / Object.isSealed
Object.freeze / Object.isFrozen
PS:只讲有什么,不讲是什么。
ECMAScript6在保证向下兼容的前提下,提供大量新特性,目前浏览器兼容情况如下:
ES6特性如下:
1.块级作用域 关键字let, 常量const
2.对象字面量的属性赋值简写(property value shorthand)
var obj = {
// __proto__
__proto__: theProtoObj,
// Shorthand for ‘handler: handler’
// Method definitions
toString() {
// Super calls
return "d " + super.toString();
// Computed (dynamic) property names
[ 'prop_' + (() =& 42)() ]: 42
3.赋值解构
let singer = { first: "Bob", last: "Dylan" };
let { first: f, last: l } = // 相当于 f = "Bob", l = "Dylan"
let [all, year, month, day] =
/^(\d\d\d\d)-(\d\d)-(\d\d)$/.exec("");
let [x, y] = [1, 2, 3]; // x = 1, y = 2
4.函数参数 - 默认值、参数打包、&数组展开(Default 、Rest 、Spread)
function findArtist(name='lu', age='26') {
function f(x, ...y) {
// y is an Array
return x * y.
f(3, "hello", true) == 6
function f(x, y, z) {
return x + y +
// Pass each elem of array as argument
f(...[1,2,3]) == 6
5.箭头函数 Arrow functions
(1).简化了形式,默认return表达式结果。
(2).自动绑定语义this,即定义函数时的this。如上面例子中,forEach的匿名函数参数中用到的this。
6.字符串模板 Template strings
var name = "Bob", time = "today";
`Hello ${name}, how are you ${time}?`
// return "Hello Bob, how are you today?"
7. Iterators(迭代器)+ for..of
迭代器有个next方法,调用会返回:
(1).返回迭代对象的一个元素:{ done: false, value: elem }
(2).如果已到迭代对象的末端:{ done: true, value: retVal }
for (var n of ['a','b','c']) {
console.log(n);
// 打印a、b、c
8.生成器 (Generators)
Class,有constructor、extends、super,但本质上是语法糖(对语言的功能并没有影响,但是更方便使用)。
class Artist {
constructor(name) {
this.name =
perform() {
return this.name + " performs ";
class Singer extends Artist {
constructor(name, song) {
super.constructor(name);
this.song =
perform() {
return super.perform() + "[" + this.song + "]";
let james = new Singer("Etta James", "At last");
james instanceof A // true
james instanceof S // true
james.perform(); // "Etta James performs [At last]"
10.Modules
ES6的内置模块功能借鉴了CommonJS和AMD各自的优点:
(1).具有CommonJS的精简语法、唯一导出出口(single exports)和循环依赖(cyclic dependencies)的特点。
(2).类似AMD,支持异步加载和可配置的模块加载。
// lib/math.js
export function sum(x, y) {
return x +
export var pi = 3.141593;
import * as math from "lib/math";
alert("2π = " + math.sum(math.pi, math.pi));
// otherApp.js
import {sum, pi} from "lib/math";
alert("2π = " + sum(pi, pi));
Module Loaders:
// Dynamic loading – ‘System’ is default loader
System.import('lib/math').then(function(m) {
alert("2π = " + m.sum(m.pi, m.pi));
// Directly manipulate module cache
System.get('jquery');
System.set('jquery', Module({$: $})); // WARNING: not yet finalized
11.Map + Set + WeakMap + WeakSet
四种集合类型,WeakMap、WeakSet作为属性键的对象如果没有别的变量在引用它们,则会被回收释放掉。
var s = new Set();
s.add("hello").add("goodbye").add("hello");
s.size === 2;
s.has("hello") ===
var m = new Map();
m.set("hello", 42);
m.set(s, 34);
m.get(s) == 34;
var wm = new WeakMap();
wm.set(s, { extra: 42 });
wm.size === undefined
// Weak Sets
var ws = new WeakSet();
ws.add({ data: 42 });//Because the added object has no other references, it will not be held in the set
12.Math + Number + String + Array + Object APIs
一些新的API
Number.EPSILON
Number.isInteger(Infinity) // false
Number.isNaN("NaN") // false
Math.acosh(3) // 1.086
Math.hypot(3, 4) // 5
Math.imul(Math.pow(2, 32) - 1, Math.pow(2, 32) - 2) // 2
"abcde".includes("cd") // true
"abc".repeat(3) // "abcabcabc"
Array.from(document.querySelectorAll('*')) // Returns a real Array
Array.of(1, 2, 3) // Similar to new Array(...), but without special one-arg behavior
[0, 0, 0].fill(7, 1) // [0,7,7]
[1, 2, 3].find(x =& x == 3) // 3
[1, 2, 3].findIndex(x =& x == 2) // 1
[1, 2, 3, 4, 5].copyWithin(3, 0) // [1, 2, 3, 1, 2]
["a", "b", "c"].entries() // iterator [0, "a"], [1,"b"], [2,"c"]
["a", "b", "c"].keys() // iterator 0, 1, 2
["a", "b", "c"].values() // iterator "a", "b", "c"
Object.assign(Point, { origin: new Point(0,0) })
13.&Proxies
使用代理(Proxy)监听对象的操作,然后可以做一些相应事情。
var target = {};
var handler = {
get: function (receiver, name) {
return `Hello, ${name}!`;
var p = new Proxy(target, handler);
p.world === 'Hello, world!';
可监听的操作: get、set、has、deleteProperty、apply、construct、getOwnPropertyDescriptor、defineProperty、getPrototypeOf、setPrototypeOf、enumerate、ownKeys、preventExtensions、isExtensible。
14.Symbols
Symbol是一种基本类型。Symbol 通过调用symbol函数产生,它接收一个可选的名字参数,该函数返回的symbol是唯一的。
var key = Symbol("key");
var key2 = Symbol("key");
key == key2
15.Promises
Promises是处理异步操作的对象,使用了 Promise 对象之后可以用一种链式调用的方式来组织代码,让代码更加直观(类似的deferred&对象)。
function fakeAjax(url) {
return new Promise(function (resolve, reject) {
// setTimeouts are for effect, typically we would handle XHR
if (!url) {
return setTimeout(reject, 1000);
return setTimeout(resolve, 1000);
// no url, promise rejected
fakeAjax().then(function () {
console.log('success');
},function () {
console.log('fail');
对于ES6,在某些方式是不是重蹈ES4的覆辙,变得复杂了;又或许几年后大家的接受能力变强了,觉得是应该这样了。我觉得还是不错的,因为它们是向下兼容的,即使复杂语法不会用,也能用自己熟知的方式,提供的语法糖也都挺实际。
阅读(...) 评论() &es6继承 vs js原生继承(es5)-爱编程
es6继承 vs js原生继承(es5)
最近在看es2015的一些语法,最实用的应该就是继承这个新特性了。比如下面的代码:
1 $(function(){
class Father{
constructor(name, age){
this.name =
this.age =
console.log(`我叫:${this.name}, 今年${this.age}岁`);
class Son extends Father{};
let son = new Son('金角大王', 200);
son.show();//return 我叫:金角大王, 今年200岁
这是一个最简单的继承。在Son类中并没有任何的自己的属性和方法,来看一下f12中的结构
也是不例外的使用了原型链来实现的继承,那么在es5中如果要实现这个继承应该怎么做?
使用babel把这段代码翻译成es5的语法,发现代码如下:
1 "use strict";
3 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i & props. i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return C }; }();
5 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : }
7 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superC }
9 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
* Created by liuyc14 on .
15 var Father = function () {
function Father(name, age) {
_classCallCheck(this, Father);
this.name =
this.age =
_createClass(Father, [{
key: "show",
value: function show() {
console.log("我叫:" + this.name + ", 今年" + this.age + "岁");
35 var Son = function (_Father) {
_inherits(Son, _Father);
function Son() {
_classCallCheck(this, Son);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Son).apply(this, arguments));
45 }(Father);
这些是babel编译完成后生成的es5语法的实现代码,看起来多了很多东西。
不着急,挑出几个重点来看一下(以后的例子都使用es5语法)
1.&_createClass 方法,创建一个类,用到了defineProperties方法,就是给第一个参数的target对象,附加所有第二个参数的属性
2.&_inherits 方法,实现继承的核心,用到了Object.create 和&Object.setPrototypeOf 方法
Object.create 方法:
这个方法接受两个参数,第一个参数为要继承的对象,第二参数为附加属性,返回一个创建后的对象。
举个例子:
1 function Father(name, age){
this.name =
this.age =
6 Father.prototype.show = function () {
console.log('我叫:' +this.name+', 今年'+this.age+'岁');
10 var obj = Object.create(Father.prototype);
11 console.log(obj.name); //return undefined
12 obj.show(); // return 我叫:undefined, 今年undefined岁
上面这个例子中,使用create方法,创建了一个obj对象,而且这个对象继承了Father.prototype对象的属性。(只有一个show方法,并没有 name 和 age 属性)
看到了这个作用以后,我们就可以使用create方法来实现es5的继承了
1 function Father(name, age){
this.name =
this.age =
6 Father.prototype.show = function () {
console.log('我叫:' +this.name+', 今年'+this.age+'岁');
10 function Son(name, age){
Father.call(this, name, age);
13 Son.prototype = Object.create(Father.prototype);
14 Son.prototype.constructor = S
15 Son.prototype.show = function () {
console.log('我是子类,我叫' + this.name + ', 今年' + this.age + '岁了');
18 var s = new Son('银角大王', 150); //return 我是子类,我叫银角大王, 今年150岁了
19 s.show();
上面的Son类在定义时,使用Father.call来继承Father的实例属性,使用Object.create方法来继承Father的原型,这样就完整的实现了继承,来看一下分析图
Son的实例s,在原型中有自己的show方法,再往上查找Father的原型,还可以看到show的原型,很清晰的层次结构
其实我们也可以不使用Object.create方法,使用Object.setPrototypeOf 方法来代替,达到同样的效果
把之前例子里第13行代码由
Son.prototype = Object.create(Father.prototype); =&
Object.setPrototypeOf(Son.prototype, Father.prototype);
这两行代码的效果是一样的,第二种方法更直观一些,就是把Son.prototype.__proto__ = Father.prototype 这样。
最后一个问题,我们如何才能向C#或者java里那样,在子类型中调用父类的方法呢?比如Son.prototype.show=function(){super.show()}这样
可以使用Object.getPrototypeOf(Son.prototype)方法来获取原型链的上一级,这样就可以获取到Father.prototype对象了,然后调用show()方法
1 Son.prototype.show = function () {
Object.getPrototypeOf(Son.prototype).show();
console.log('我是子类,我叫' + this.name + ', 今年' + this.age + '岁了');
但是调用Son的show方法,会log出:&我叫:undefined, 今年undefined岁;&我是子类,我叫银角大王, 今年150岁了
为什么会有undefined?看看刚才我们的f12结构图,Father.prototype中是没有name 和 age 属性的,那么怎么办?使用call方法啊!
下面贴出完整的类继承实现代码:
1 function Father(name, age){
this.name =
this.age =
6 Father.prototype.show = function () {
console.log('我叫:' +this.name+', 今年'+this.age+'岁');
10 function Son(name, age){
Father.call(this, name, age);
13 Object.setPrototypeOf(Son.prototype, Father.prototype);
14 Son.prototype.constructor = S
15 Son.prototype.$super = Object.getPrototypeOf(Son.prototype);//使用$super属性来指向父类的原型
16 Son.prototype.show = function () {
this.$super.show.call(this);
console.log('我是子类,我叫' + this.name + ', 今年' + this.age + '岁了');
20 var s = new Son('银角大王', 150);
21 s.show();
OK,今天的总结写完了,跟流水账一样,大家凑活看吧
版权所有 爱编程 (C) Copyright 2012. . All Rights Reserved.
闽ICP备号-3
微信扫一扫关注爱编程,每天为您推送一篇经典技术文章。这种shorthand property是属于ES6还是ES5? - CNode技术社区
积分: 1580
我只想做差异化、和别人不同的东西(嘿嘿,其实是因为我有些懒,不想和别人硬拼)
const obj = {
lukeSkywalker,
anakinSkywalker,
episodeOne: 1,
twoJediWalkIntoACantina: 2,
episodeThree: 3,
mayTheFourth: 4
第一次听说这个
5的时候就有了把?
module.exports = {
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
服务器赞助商为
,存储赞助商为
,由提供应用性能服务。
新手搭建 Node.js 服务器,推荐使用无需备案的

我要回帖

更多关于 原生支持手柄的手游 的文章

 

随机推荐