Vector's Blog


  • 首页

  • 归档

  • 标签

ES新特性

发表于 2018-07-23   |     |   阅读次数

模板字符串

1
2
let a = ~~(Math.random())*10;
console.log(`hello,${a}`);

扩展运算符

1
2
3
4
5
6
7
8
const a = [1,2,3];
const b = [4,...a,6];
console.log(b); //[4,1,2,3,6]
const {c,d,...z} = {c:1,d:2,e:4,f:6};
console.log(c) //1
console.log(d) //2
console.log(z) //{e:4,f:6}

Array.find

1
2
3
4
5
6
7
8
const arr = [
{name:'aa',value:'1',type:'a'},
{name:'bb',value:'2',type:'b'},
{name:'cc',value:'3',type:'c'},
{name:'cc',value:'4',type:'d'}
]
const obj = arr.find(item => item.name === 'aa' && item.value === '1');
console.log(obj) // {name:'aa',value:'1',type:'a'}

跨模块常量

1
2
3
//a.js
export const A = 1;
export const B = 2;
1
2
3
4
//b.js
import ^ as hello from ‘./a.js’;
console.log(hello.A);//1
console.log(hello.B);//2

解构赋值

如果解构不成功。变量的值就等于undefined

解构赋值允许指定默认值

1
2
3
4
var [ foo = true ] = [];
foo // true
[ x,y = ‘b’ ] = [‘a’] //x=’a’,y=’b’
[ x,y = ‘b’] = [‘a’, undefined] //x=’a’ ,y=’b’

注意:ES6内部使用严格相等运算符(===)判断一个位置是否有值。所以,如果一个数组成员不严格等于undefined,默认值是不会生效的。

阅读全文 »

Command Line Interface

发表于 2018-07-23   |     |   阅读次数

步骤

创建文件夹

lxl-cli-demo

执行命令

cd lxl-cli-demo

npm init -y

创建文件

./bin/index.js

1
2
#!/usr/bin/env node
console.log('hello cli')

修改文件

package.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"name": "lxl-cli-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin":{
"lxl-cli": "./bin/index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

全局安装

npm install -g

使用

打开cmd,输入lxl-cli

Nodejs上传图片

发表于 2017-04-03   |     |   阅读次数

新建项目文件夹

在项目目录下打开命令窗口,输入

npm install formidable --save-dev

新建tmp,img文件夹

新建server.js,starter.js,uploader.js,shower.js文件

文件内容如下所示

阅读全文 »
1…345…8
林某亮

林某亮

满地都是六便士
他却抬头看见了月亮

22 日志
3 标签
GitHub Weibo
© 2018 林某亮
由 Hexo 强力驱动
主题 - NexT.Pisces