博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
es6零碎知识点整理
阅读量:5882 次
发布时间:2019-06-19

本文共 2286 字,大约阅读时间需要 7 分钟。

module

  • components/HelloWorld.vue
import { a } from "@/modules";import b from "@/modules";export default {  mounted() {    console.log(a);    b();  }};复制代码
  • modules/index.js
let a = 'JonSnow'let b = 'Cercei'export {    a}export default () => console.log(b);复制代码

  • components/HelloWorld.vue
import b from "@/module";export default {  mounted() {    b().then(res => {      console.log(res);    });  }};复制代码
  • modules/index.js
export default () => new Promise((resolve, reject) => {    setTimeout(() => {    	resolve('es6 module')    }, 200)})复制代码

class

class Person {  constructor(name, age) {    this.name = name;    this.age = age;  }  say() {    console.log(`${
this.name}'s age is ${
this.age}`); }}class Student extends Person { constructor(name, age, sex) { super(name, age); this.sex = sex; } saySex() { console.log( `${
this.name}'s age is ${
this.age} and his sex is ${
this.sex}` ); }}let JonSnow = new Student("JonSnow", 21, "男");JonSnow.say();JonSnow.saySex();console.log(JonSnow);console.log(JonSnow instanceof Student);console.log(JonSnow instanceof Person);复制代码

includes && indexOf

let arr = [1, 2, 3];console.log(arr.includes(1));console.log(arr.indexOf(100));复制代码

全局作用域与函数作用域

var a = 12;function fn() {  console.log(a);  var b = 13;  if (true) {    var c = 14;    console.log(b);  }  console.log(c);}fn();console.log(c);//报错复制代码

函数执行完后,变量就被销毁了

使用undefined传参

function myFunction(x = 1, y = 2, z = 3) {  console.log(x, y, z);//1,7,9}myFunction(undefined, 7, 9);复制代码

参数运算

function myFunction(x, y, z = x + y) {  console.log(x, y, z);//1,2,3}fn(1, 2);复制代码

push

let a1 = [1];let a2 = [2, 3, 4];// a1.push(2, 3, 4);a1.push(...a2);console.log(a1);复制代码

忽略数组中的某些值

let [a, , b] = [1, 2, 3];console.log(a); //1console.log(b); //3复制代码

使用展开语法

let [a, ...b] = [1, 2, 3];console.log(a); // 1console.log(b); //[2,3]复制代码

let [a, , ...b] = [1, 2, 3, 4, 5];console.log(a); //1console.log(b); //[3,4,5]复制代码

let [a, b, c = 3] = [1, 2];console.log(a); //1console.log(b); //2console.log(c); //3复制代码

function myFunction([a, b, c = 3] = [1, 2, 3]) {  console.log(a, b, c);//1 2 3}myFunction();复制代码

function myFunction([a, b, c = 3] = [1, 2, 3]) {  console.log(a, b, c);//1 2 3}myFunction(undefined);复制代码

转载于:https://juejin.im/post/5ce4b256f265da1bb80c0402

你可能感兴趣的文章
Maven项目
查看>>
B树 B+树 红黑树
查看>>
How to check in Windows if you are using UEFI
查看>>
【LeetCode】Divide Two Integers
查看>>
IOS使用Jenkins进行持续集成
查看>>
fiddler抓包工具
查看>>
git 修改客户端用户名和密码
查看>>
FileStream读写文件【StreamWriter 和 StreamReader】
查看>>
Github 结合 Hexo 搭建轻量博客
查看>>
vs2017 git凭证问题
查看>>
梦断代码 读后感2
查看>>
nodejs 安装 postgresql module
查看>>
Kth Largest Element in an Array - LeetCode
查看>>
GVIM设置背景颜色
查看>>
存储的瓶颈终篇(8)
查看>>
总部关于数据集成工程师的招聘要求
查看>>
[git]一个本地仓库,多个远程仓库
查看>>
POJO
查看>>
大数据分页实现与性能优化
查看>>
Vue --- :is
查看>>