大学生笔记

1.什么是Generator,与普通函数有什么区别
// Generator 函数,可以通过 yield 关键字,把函数的执行流挂起,为改变执行流程提供了可能
区别
// 1.一是在 function 后面,函数名之前有个 * ;
// 2.函数内部有 yield 表达式。
// 3.其中 * 用来表示函数为 Generator 函数,yield 用来定义函数内部的状态。
2.await 特性是什么
await 关键字仅在 async function 中有效。
// 如果在 async function 函数体外使用 await ,你只会得到一个语法错误。
// Promise 对象:await 会暂停执行,等待 Promise 对象 resolve,然后恢复 async 函数的执行并返回解析值。
// 非 Promise 对象:直接返回对应的值。
3.什么是Proxy对象
一个 Proxy 对象由两个部分组成: target 、 handler 。在通过 Proxy 构造函数生成实例对象时,需要提供这两个参数。
// target 即目标对象, handler 是一个对象,声明了代理 target 的指定行为
// 严格模式set失效,开启严格模式方法"use strict";
4.请写出防抖的2种方式
var num = 1;
let times;
先执行
content.onmousemove = function (){
// let obj = times;
// clearTimeout(times);
// times = setTimeout(()=>{
// times = null;
// },1000)
// if(!obj){
// console.log(typeof !obj);
// content.innerHTML = num++;
// }
// };
后执行
content.onmousemove = function (){
// clearTimeout(times);
// times = setTimeout(()=>{
// content.innerHTML = num++;
// },1000)
// };

5.请写出节流的2种方式
延时器
var time;
// content.onmousemove = function(){
// if(!time){
// time = setTimeout(()=>{
// time = null;
// content.innerHTML = num++;
// },1000)
// }
//时间戳
// var content = document.getElementById(“content”);
// var num = 1;
// var timeNew = 0;
// content.onmousemove = function(){
// var timeOld = Date.now();
// if(timeOld-timeNew>1000){
// timeNew = timeOld;
// content.innerHTML = num++;
// }
// }
6.请写出导入导出的所有方式
// 第一种
// import {userName,age} from “./day28.js”
// 第二种
// import {userName as aaa} from “./day28.js”
// 第三种
// import abc from “./day28.js”
// 第四种
// import * as abc from “./day28.js”

// 第一种
export {userName,age}
// 第二种
// export {userName as names}
// 第三种
// export default userName;
7.请使用js通过get和post调用接口http://index.com数据并接收,get和post传id=99

get方式
let http = new XMLHttpRequest();
http.open(“get”,“http://index.com?id=99”);
http.send();
http.onreadystatechange = function(){
if(http.readyState4 && http.status201){
console.log(JSON.parse(http.responseText));
}
}
Post方式
let http = new XMLHttpRequest();
http.open(“post”,“http://index.com”);

表单格式
//http.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded”)
// http.send(JSON.stringify(id=99));
JSON格式
// http.setRequestHeader(“Content-Type”,“application/json”)
// http.send(JSON.stringify({
// “id”:99
// }))
http.onreadystatechange = function(){
console.log(JSON.parse(http.responseText));
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值