1、判断数组方式
- instanceof
let arr = []
console.log(arr instanceof Array) // true
- constructor
let arr = []
console.log(arr.constructor === Array) // true
- Array.isArray
let arr = []
console.log(Array.isArray(arr)) // true
- Object.prototype.toString.call
let arr = []
console.log(Object.prototype.toString.call(arr) === '[object Array]') // true
2、instanceof 实现原理
function myInstanceof (left, right) {
let proto = Object.getPrototypeOf(left);
while (true) {
if (proto === null) {
return false;
}
if (proto === right.prototype) {
return true;
}
proto = Object.getPrototypeOf(proto);
}
}
3、怎么判断判断空对象
- Object.keys()
- JSON.stringify()
let obj = {
name: "cxy"
}
console.log(JSON.stringify(obj) == '{}')
- for in + hasOwnProperty
function isEmptyObject(obj){
// for in 可以遍历到继承的可枚举属性
for(const key in obj){
// 判断自身属性
if(obj.hasOwnProperty(key)){
return false;
}
}
return true;
}
4、Vue组件懒加载原理
5、Vue开发最佳实践
- v-show 和 v-if 区分场景使用
- v-for 遍历必须为 item 添加 key,最好不要使用 index
- v-for 和 v-if 避免同时使用
- 长列表性能优化
- 优化无限列表性能,采用窗口化技术
- 图片资源懒加载
- 路由懒加载
- 第三方插件按需引入,比如 element-ui 按需引入
6、V-model原理
ustbhuangyi.github.io/vue-analysi…
7、CommonJS 与 ES6 Modules 规范的区别
-
CommonJS模块是运行时加载,ES6 Modules是编译时输出接口
-
CommonJS输出是值的拷贝;ES6 Modules输出的是值的引用,被输出模块的内部的改变会影响引用的改变
-
CommonJs导入的模块路径可以是一个表达式,因为它使用的是require()方法;而ES6 Modules只能是字符串
-
CommonJS this指向当前模块,ES6 Modules this指向undefined
-
ES6 Modules中没有这些顶层变量:arguments、require、module、exports、__filename、__dirname