Introduction to ES6上课笔记

课程链接:https://scrimba.com/g/gintrotoes6

这个网站有几个热门的前端技术栈的免费课程,上课体验除了英语渣只能看代码理解听老师讲的一知半解之外,是极佳的学编程的网站了。你跟老师同一个编译器上编译代码,超强体验!!如果跟我一样英语渣,最好结合一下ES6相关书看一下,这样听不懂也看代码也可以知道点在哪里了。

 

1.Template Literals

 let word1 = 'Liu';

let word2 = 'li';

旧:

const fullName = word1 + ''+word2;

fullName = word1 + ''\n + word2;     //Liu

                                                           li

新: 

const fullName = `${word1} ${word2}`;   //Liu li

fullName =  `${word1}

${word2}`;     //Liu

                       li

 

2.Destructuring Objects

const personalInformation = {

firstName: 'Dylan',
lastName: 'Israel',
city: 'Austin',
state: 'Texas',
zipCode: 73301
};
const {firstName, lastName} = personalInformation;
const {firstName: fn, lastName: ln} = personalInformation;
console.log(`${firstName} ${lastName}`);
console.log(`${fn} ${ln}`);

3.Destructuring Arrays

let [firstName, middleName, lastName] = ['Dylan', 'Coding God', 'Israel'];
lastName = 'Clements';
console.log(lastName)    //Clements

4.Object Literal

function addressMaker(city, state) {
const newAdress = {newCity: city, newState: state};
console.log(newAdress);   // {newCity: "Austin", newState: "Texas"}
}
addressMaker('Austin', 'Texas');
===========ES6====
function addressMaker(city, state) {
const newAdress = {city, state};
console.log(newAdress);   // {city: "Austin", state: "Texas"}
}
addressMaker('Austin', 'Texas');

 

5.Object Literal(Challenge)

function addressMaker(address) {

const {city, state} = address;
const newAddress = {
city,
state,
country: 'United States'
}; 
}
addressMaker({city: 'Austin', state: 'Texas'});

6.For of Loop

let fullName = "Dylan Coding God Israel";
for (const char of fullName) {
console.log(char);                //D y l a n ....
}

7.For of Loop(Challenge)

let incomes = [62000, 67000, 75000];
for (let income of incomes) {
income += 5000;
}
console.log(incomes);     // [62000, 67000, 75000]
 

8.Spread Operator

let example1 = [1,2,3,4,5,6];
let example2 = [...example1];
example2.push(true);
console.log(example2);   //[1,2,3,4,5,6,true]

9.Rest Operator

function add(...nums){
console.log(nums)    //[4,5,6,7,8]
add(4,5,6,7,8);

10.Arrow Functions

旧:
function add(...nums) {
let total = nums.reduce(function (x, y) {
return x+y;
}); 
console.log(total); //36
}
add(4, 5, 7, 8, 12)
新:
function add(...nums) {
let total = nums.reduce((x, y) => {
return x+y;
});
console.log(total);
}

add(4, 5, 7, 8, 12)
或者是进一步的
function add(...nums) {
let total = nums.reduce((x, y) => x+y);
console.log(total);
}
add(4, 5, 7, 8, 12)

11.Default  Param

function add(numArray = []) {
let total =0;
numArray.forEach((element) => {
total += element;
});
console.log(total);    //0
}
add();

12.includes(除IE)

旧:
let numArray = [1,2,3,4,5];
console.log(numArray.indexOf(0))      //-1
新:
let numArray = [1,2,3,4,5];
console.log(numArray.includes(0))     //false

13.Let&Const

var:
if (false) {
var example=5;
}
console.log(example)   //null
let:
if (false) {
let example =5;
}
console.log(example)   //ReferenceError
const:
const example = [];
example =3;
console.log(example)   //Error
 
const example=[];
example.push(3);
console.log(example)   //[3]
 
const example = {};
example.firstName ='Dylan';
console.log(example)  //{firstName:"Dylan"}

14.padStart()&padEnd()

let example = 'Dylan';
console.log(example.padStart(10, 'a'));  //aaaaaDylan
 
let example = 'Dylan';
console.log(example.padEnd(10, 'a'));  //Dylanaaaaa
 
let example = 'Dylan Irseal';
console.log(example.padEnd(10, 'a'));  //Dylan Irseal

15.Import&Export 

---------文件Animal.js-----------
export class Animal {
constructor(type, legs) {
this.type = type;
this.legs = legs;
makeNoise(loudNoise = "loud"){
console.log(loudNoise);
}
}
---------文件index.js----------
import { Animal } from './animal.js';
let cat = new Animal('Cat', 4);
cat.legs = 3;
cat.makeNoise("meow");  //meow
console.log(cat.legs)    //3

16.Classes

-------文件Animal.js----------
export class Animal {
constructor(type, legs) {
this.type = type;
this.legs = legs;
makeNoise(loudNoise = "loud"){
console.log(loudNoise);
}
 
get metaData(){
return `Type:${this.type},Legs:${this.legs}`;
}
 
static return10(){
return 10;
}
}
 
export class Cat extends Animal{
constructor(type,legs,tail){
super(type,legs);
this.tail = tail;
}
makeNoise(loudNoise = "meow"){
console.log(loudNoise);
}
}
------文件index.js--------
import { Animal ,Cat} from './animal.js';
let cat = new Cat('Cat',4,"long");
console.log(Animal.return10());  //10
console.log(cat.metaData);  // Type:Cat,Legs:4
 
cat.makeNoise(); //meow
console.log(cat.metaData) //Type:Cat,Legs:4
console.log(cat.tail)//long

17.Trailing Commas

没听懂

18.Async&Await

const apiUrl = 'https://fcctop100.herokuapp.com/api/fccusers/top/alltime';

function getTop100Campers() {
fetch(apiUrl)
.then((r) => r.json())
.then((json) => {
console.log(json[0])
}).catch((error) => {console.log('faild');});
}
getTop100Campers();  //{username:"sjames1958gm",img:"https//avatars1.githubusercontent.com/u/4639625?v=4",alltime:8826,recent:104,lastUpadate:"2018-04-04T09:10:12.456Z"}
-----await---
const apiUrl = 'https://fcctop100.herokuapp.com/api/fccusers/top/alltime';

function getTop100Campers() {
const response = await fetch(aipUrl);
const json = await response.json();
 
console.log(json[0]);
}
getTop100Campers();  //{username:"sjames1958gm",img:"https//avatars1.githubusercontent.com/u/4639625?v=4",alltime:8826,recent:104,lastUpadate:"2018-04-04T09:10:12.456Z"}
-----async----
没听懂
function resolveAfter3Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 3000);
});
}

// resolveAfter3Seconds().then((data) => {
// console.log(data);
// });

async function getAsyncData() {
const result = await resolveAfter3Seconds();
console.log(result);             //resolved
}

getAsyncData();

18.Sets

const exampleSet = new Set([1,1,1,1,2,2,2,2]);
exampleSet.add(5);
exampleSet.add(5).add(17);
console.log(exampleSet.size);   //4
---------delete()----------
console.log(exampleSet.delete(5));  //true
console.log(exampleSet.size);   //3
----------clear()-----
exampleSet.clear();
console.log(exampleSet.size);  //0

转载于:https://www.cnblogs.com/GuliGugaLiz/p/10335067.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/412356.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[vue] 你了解什么是高阶组件吗?可否举个例子说明下?

[vue] 你了解什么是高阶组件吗?可否举个例子说明下? 高阶组件 高阶组件介绍 vue 高阶组件的认识,在React中组件是以复用代码实现的,而Vue中是以mixins 实现,并且官方文档中也缺少一些高阶组件的概念,因为在vue中实现…

修改Tomcat端口号

8080是Tomcat服务器的默认端口号。我们可以通过修改Tomcat/conf文件夹下的主配置文件server.xml来更改端口号。用记事本打开server.xml文件&#xff0c;找出出现以下代码的部分&#xff1a; <!-- A "Connector" represents an endpoint by which requests are rec…

序列化与反序列化的简单认识

把对象转换为字节序列的过程称为对象的序列化。  把字节序列恢复为对象的过程称为对象的反序列化。  对象的序列化主要有两种用途&#xff1a;  1&#xff09; 把对象的字节序列永久地保存到硬盘上&#xff0c;通常存放在一个文件中&#xff1b;  2&#xff09; 在网络…

[vue] vue怎么缓存当前的组件?缓存后怎么更新?

[vue] vue怎么缓存当前的组件&#xff1f;缓存后怎么更新&#xff1f; keep-alive 通过actived钩子个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

添加多个tomcat服务目录

tomcat默认的web服务的根目录为Tomcat 6.0\webapps\Root 如果将JSP文件保存至Root目录中&#xff0c;应当在浏览器的地址栏中输入&#xff1a; http://localhost:8080/MyJsp.jsp 我们也可以建立新的Web服务目录。假设要将c:\TEMP作为服务目录&#xff0c;并让用户使用temp虚…

JMeter 性能测试实例

一、性能测试分类&#xff1a; 1、基准测试 2、并发测试 3、负载测试 4、压力测试 1、基准测试&#xff1a; 也是单用户测试&#xff0c;测试环境确定以后&#xff0c;对业务模型中的重要业务做单独的测试&#xff0c;获取单用户运行时的各项性能指标&#xff0c;为多用户并发测…

[vue] vue和微信小程序写法上有什么区别?

[vue] vue和微信小程序写法上有什么区别&#xff1f;写了vue项目和小程序&#xff0c;发现二者有许多相同之处&#xff0c;在此想总结一下二者的共同点和区别。 一、生命周期 先贴两张图&#xff1a; vue生命周期 小程序生命周期 相比之下&#xff0c;小程序的钩子函数要简…

java 转换url中文参数

当使用request对象获取用户提交的汉字字符时&#xff0c;会出现乱码问题&#xff0c;所以对含有汉子字符的信息必须进行特殊的处理。 首先&#xff0c;将获取的字符串用IOS-8859-1进行编码&#xff0c;并将编码存放到一个字节数组中&#xff0c;然后再将这个数组转换为字符串对…

[vue] vue开发过程中你有使用什么辅助工具吗?

[vue] vue开发过程中你有使用什么辅助工具吗&#xff1f; #335 vue-devtools个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

Django学习之十一:真正理解Django的路由分发和反解url原理

目录 URL Dispatcher简介模式概念对比URLPattern 与 URLResolver (多态的体现)构建子路由几种方式反解url算法逻辑URL Dispatcher 简介 django的url dispatcher 设计是基于一个url mapper来工作的。 这个url mapper主要用在两个方向&#xff1a; url 匹配到 视图通过提供的标识…

Unable to locate tools.jar

初使用ant的时候&#xff0c;打开cmd&#xff0c;使用ant -version查看ant版本以测试ant是否能正常工作&#xff0c; 我先前是已经将ant的bin目录添加进入环境变量中了&#xff0c;后来运行中报了这么一个错误&#xff1a; 解决办法就是将C:\Program Files (x86)\Java\jdk1.6.…

[vue] 你们项目为什么会选vue而不选择其它的框架呢?

[vue] 你们项目为什么会选vue而不选择其它的框架呢&#xff1f; Vue.js是一个轻巧、高性能、可组件化的MVVM库&#xff0c;同时拥有非常容易上手的API&#xff1b;vue是单页面应用&#xff0c;使页面局部刷新&#xff0c;不用每次跳转页面都要请求所有数据和dom&#xff0c;这…

你所忽略的,覆盖equals时需要注意的事项《effective java》

我们都知道Object的equals的比较其实就是的比较&#xff0c;其实是内存中的存放地址的比较。正常逻辑上&#xff1a;类的每个实例本质上都是唯一的。 在工作中我们实际的业务逻辑往往有可能出现一些相对特殊的需求需要对equals方法进行重写&#xff0c;那么重写equals需要注意哪…

[vue] vue在开发过程中要同时跟N个不同的后端人员联调接口(请求的url不一样)时你该怎么办?

[vue] vue在开发过程中要同时跟N个不同的后端人员联调接口&#xff08;请求的url不一样&#xff09;时你该怎么办&#xff1f; devServer中把所有的服务人员的地址代理都写进去&#xff0c; 然后动态更改接口的baseUrl&#xff0c;这样切换不同后端人员的时候不用重启个人简介…

使用 bat 文件管理计算机服务

echo off title 计算机服务管理 :allstart cls echo 曾俊工作室 echo 1.SQL Server 2008 服务开启、关闭 echo 2.MySQL 服务开启、关闭 echo 3.Oracle 11g 服务开启、关闭 echo e.退出 set in set /p in请输入: if "%in%""1" goto sqlserver if "…

处女座与复读机

链接&#xff1a;https://ac.nowcoder.com/acm/contest/327/G来源&#xff1a;牛客网 一天&#xff0c;处女座在牛客算法群里发了一句“我好强啊”&#xff0c;引起无数的复读&#xff0c;可是处女座发现复读之后变成了“处女座好强啊”。处女座经过调查发现群里的复读机都是失…

[vue] 如何解决vue打包vendor过大的问题?

[vue] 如何解决vue打包vendor过大的问题&#xff1f; 1、在webpack.base.conf.js新增externals配置&#xff0c;表示不需要打包的文件&#xff0c;然后在index.html中通过CDN引入externals: {"vue": "Vue","vue-router": "VueRouter"…

jquery ajax 解决跨域访问问题

当使用jquery ajax进行跨域请求时&#xff0c;会出现Access-Control-Allow-Origin错误 //获取验证码 var send_status true; $(#pull_code).click(function () {if (!send_status) {return false;}var phone $(#phone).val();if (!phone) {alert(请输入手机号码!);return fa…

测试网络

|||||106.13.4.129|||||转载于:https://www.cnblogs.com/Sendige/p/10343124.html

bootstrap 一排5个_BootStrap从基础到项目实战_第1季_03章_02_CSS样式栅格系统实例

目标目标一、理解什么是栅格布局目标二、掌握栅格布局具体应用目标三、掌握BootStrap通用CSS样式(排版、代码、代码、表单、按钮、图片、辅助类、响应式工具)内容一、BootStrap全局CSS之 - 栅格系统实例1.1 栅格系统实例实战前的理论准备通过下面的截图可以比较清楚的来查看Boo…