一、什么是原型原型链
原型:
var a = [1,2,3];
a.__proto__ === Array.prototype; // true
原型链:
function Parent(month){
this.month = month;
}
var child = new Parent('Ann');
console.log(child.month); // Ann
console.log(child.father); // undefined
在child中查找某个属性时,会执行下面步骤
:
二、什么是防抖节流(都为为了降低频率)
防抖:是指在事件触发n秒后再执行回调,如果在n秒内再次被触发,则重新计算时间。(就是在触发某个事件后,在下一次触发之前,中间的间隔时间如果超过设置的时间才会发送请求,一直触发就不会发送请求) 最后一次事件操作即可,不在意过程,结果是最后一次的事件操作
主要应用场景有:
a、scroll事件滚动触发,
b、搜索框输入查询
c、表单验证
d、按钮提交事件
e、浏览器窗口缩放,resize事件
普通写法:
var btn = document.querySelector('button')
var tiem = null
btn.onclick = function () {
clearTimeout(tiem)
tiem = setTimeout(() => {
console.log('111');
}, 1000)
}
//防抖还可以引用lodash插件 官方推荐使用 _ 命名
//这个函数能够包装一个函数,传递一个函数进去, debounce
//他就会产生一个新的函数,并且这个函数就具备了防抖效果,底层就是用定时器
var btn = document.querySelector('button')
btn.onclick = _.debounce(function () {
console.log('111');
}, 1000)
节流:是指如果持续触发某个事件,则每隔n秒执行一次,降低频率,依然想让她频繁触发,只不过不那么频繁
主要应用场景:
a、DOM元素的拖拽功能实现
b、射击游戏类
c、计算鼠标移动的距离
d、监听scroll事件
普通写法
var btn = document.querySelector('button')
var flag = true
btn.onclick = function () {
if (flag) {
flag = false
console.log('111');
setTimeout(() => {
flag = true
}, 1000)
}
}
// 使用lodash插件 throttle
var btn = document.querySelector('button')
btn.onclick = _.throttle(function () {
console.log('111');
}, 1000)
三、Js数据类型
基本数据类型(放在栈里):Number、String、Boolean、Null、 Undefined、Symbol(ES6)
引用数据类型(放在堆里):Array、function、 Object(在JS中除了基本数据类型以外的都是对象,数组是对象,函数是对象,正则表达式是对象)
四、如何检测数据类型(4 种)
1、typeof
var str = '字符串类型';
var num = 123;
var bool = true;
var bignum = BigInt("1234567890123456789012345678901234567890");
var d = undefined;
var n = null;
var s = Symbol('foo');
var obj = { a: 1 };
var arr = [1, 2];
console.log(typeof str);//String
console.log(typeof num);//Number
console.log(typeof bool);//Boolean
console.log(typeof bignum);//BigInt
console.log(typeof d);//Undefined
console.log(typeof n);//Object
console.log(typeof s);//Symbol
console.log(typeof obj);//Object
console.log(typeof arr);//Object
2、instanceof
// 可以区分复杂数据类型
console.log([] instanceof Array); //true
console.log({} instanceof Object); //true
3、Object.prototype.toString.call()(对象原型链判断方法)
console.log(Object.prototype.toString.call("123")) // --------> [object String]
console.log(Object.prototype.toString.call(123)) //--------> [object Number]
console.log(Object.prototype.toString.call(true)) //--------> [object Boolean]
console.log(Object.prototype.toString.call([1, 2, 3])) //--------> [object Array]
console.log(Object.prototype.toString.call(null)) //--------> [object Null]
console.log(Object.prototype.toString.call(undefined)) //--------> [object Undefined]
console.log(Object.prototype.toString.call({ name: 'Hello' })) //--------> [object Object]
console.log(Object.prototype.toString.call(function () { })) //--------> [object Function]
console.log(Object.prototype.toString.call(new Date())) //--------> [object Date]
console.log(Object.prototype.toString.call(/\d/)) //--------> [object RegExp]
console.log(Object.prototype.toString.call(Symbol())) //--------> [object Symbol]
4、constructor(用于引用数据类型)
// 可以检测其构造函数
console.log([].constructor === Array); // true
console.log({}.constructor === Object);// true
function Person() { }
console.log(new Person().constructor === Person);// true
// 原型链不会干扰
console.log([].constructor === Object); // false
五、es6新特性
使用let,const声明变量,字符串、数组、对象的解构赋值,set,map构造函数的应用,promise异步编程解决方案,async,asait,请求后台数据解构的方法,使用class类构造函数以及继承,module的暴露和引用。
async 函数是什么?
async 关键字,用来修饰函数,把这种函数称之为async函数
async 是es7中,引入的,一个用于异步编程的一种解决方案;
async函数返回一个 Promise 对象,可以使用then方法添加回调函数。
async函数内部return语句返回的值,会成为then方法回调函数的参数
await:
await命令与async配合使用,正常情况下,await命令后面是一个 Promise 对象,返回该对象的结果。
如果不是 Promise 对象,就直接返回对应的值。如果函数内使用了await,外层函数必须要用async修饰
当函数执行的时候,一旦遇到await就会先返回,等到同步操作完成,再接着执行函数体内后面的语句。
六、箭头函数和普通函数的区别
七、深拷贝浅拷贝
八、vue的生命周期
九、 为什么data是一个函数
十、组建通信
父传子:props
子传父:$emit 需要绑定事件
全局事件总线
vuex
ref/$refs
十一、http状态码
十二、什么是vuex
十三、什么是Css预处理器
十四、小程序的生命周期
1:用户首次打开小程序,触发 onLaunch(全局只触发一次)。
2:小程序初始化完成后,触发onShow方法,监听小程序显示。
3:小程序从前台进入后台,触发 onHide方法。
4:小程序从后台进入前台显示,触发 onShow方法。
5:小程序初始化完成后,页面首次加载触发onLoad,只会触发一次。
6:首次显示页面,会触发onReady方法,渲染页面元素和样式,一个页面只会调用一次。
十五、uniapp的生命周期