不积跬步无以至千里。
【Step-By-Step】高频面试题深入解析 / 周刊01
【Step-By-Step】高频面试题深入解析 / 周刊02
【Step-By-Step】高频面试题深入解析 / 周刊03
【Step-By-Step】高频面试题深入解析 / 周刊04
【Step-By-Step】高频面试题深入解析 / 周刊05
【Step-By-Step】高频面试题深入解析 / 周刊06
【Step-By-Step】高频面试题深入解析 / 周刊07
不积跬步,无以至千里;
写下你的理解~
var a = 5;
function todo() {
var a = 9;
return function() {
a = 7;
}
}
todo()();
console.log(a);
ES5定义了6种数据类型,number,String,Boolean,Undefined,Null,Object; ES6新增了第七种数据类型: Symbol类型;
null 是对象, 可以用 typeof null === Object 或者 Object.prototype.toString(null) 测试
简单类型是值传递,复杂类型是地址传递
1、new绑定:函数是否通过new调用,是的话this绑定的是新创建的对象
(前提是构造函数没有中没有返回对象或者function)
2、显式绑定:函数是否通过call,apply,bind调用,是的话this绑定的就是指定对象
(如果传入为null或undefined则被忽略,实际应用的是默认绑定)
3、隐式绑定:函数是否为对象所调用,是的话this绑定的是该对象,如xx.fun()
4、如果不是以上情况,就属于默认绑定,分两种情况:
严格模式:绑定到undefined
非严格模式:绑定到全局对象
注:特殊情况:箭头函数,它本身是没有this的,它的this继承于外层代码块的this
1.父子组件之间参数传递
2.兄弟组件之间参数传递
函数节流 和 函数防抖 :
两者核心:使用setTimeout 和 clearTimeout 限制一个方法被频繁的触发。已达到减少请求的次数,减少服务器的压力。
参考上面的 https://www.jianshu.com/p/091c5fb96112 写了一遍
/函数节流(throttle)/
function throttle(fn,interval = 300){
let canRun = true;
return function(){
if(!canRun) return;
canRun = false;
setTimeout(()=>{
fn.apply(this,arguments);
canRun = true;
},interval)
}
}
/函数防抖(debounce)/
function debounce(fn,interval = 300){
let timeout =null;
return function() {
clearTimeout(timeout) // 清除时间
timeout = setInterval(()=>{
fn.apply(this,arguments);
},interval);
}
}
this指向的问题可以总结为:谁调用指向谁。具体的细节如下:
严格模式下:
this指向undefined
非严格模式下:
1、this指向window
2、如果是对象调用,那么指向该对象,如果是函数调用,那么指向该函数(箭头函数除外,在箭头函数中,指向外层函数)
3、如果调用了apply、call、bind函数,则指向自定义指针空间
如:
flattenDeep([1, [2, [3, [4]], 5]]) // [ 1, 2, 3, 4, 5 ]
JS 中分为七种内置类型,七种内置类型又分为两大类型:基本类型和对象(Object)
基本类型有六种: null,undefined,boolean,number,string,symbol
基本数据类型把数据名和值直接存储在栈当中
复杂数据类型在栈中存储数据名和一个堆的地址,在堆中存储属性及值,访问时先从栈中获取地址,再到堆中拿出相应的值
参考文档:https://www.cnblogs.com/alenhx/p/9048144.html
函数防抖:n秒内只执行一次函数,如果n秒以内重新触发函数,则重新计时n秒去执行函数。使用场景:搜索时,等用户输入完几秒钟才去发送请求
函数节流:n秒内只执行一次,如果n秒内重新触发函数,不执行,等到n秒时触发再去执行。
1,防抖示例:
const timer = null;
function fangDou(){
clearTimeout(timer) //清除上一次的定时器
timer = setTimeout(() => {
console.log(1)
},3000)
}
2,节流示例:
const time = 0;
function jiuLIu(){
if(time -5000 < 0){ //5秒内再触发直接return不予执行
return
}
console.log(123)
time = new Date()
}
上周五刚复习过防抖,趁热打铁,巩固一下节流~
事件代理就是在祖先级DOM元素绑定一个事件,当触发子孙级DOM元素的事件时,利用事件流的原理来触发绑定在祖先级DOM的事件
事件代理就是在祖先级DOM元素绑定一个事件,当触发子孙级DOM元素的事件时,利用事件流的原理来触发绑定在祖先级DOM的事件
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.