wsmdyj / interview Goto Github PK
View Code? Open in Web Editor NEW📄 Some interview experience
📄 Some interview experience
// 深浅拷贝
// 数据分为基本数据类型(undefined,null,number,String,boolean,symbol)
// 对象数据类型(array,function)
// 浅拷贝只复制指向某个对象的指针,而不是复制对象本身,新旧对象还是共享同一块内存
// 深拷贝会创建一个一模一样的对象,新对象跟去原对象不共享内存,修改新对象不会改到原对象
// 浅拷贝的实现方式
// 直接给变量赋一个值
// let obj = {username: 'kobe', age: 39, sex: {option1: '男', option2: '女'}}
// let obj1 = obj
// obj1.sex.option1 = '不男不女'
// console.log(obj, obj1)
// Object.assign()方法
// let obj = {
// username: 'kobe'
// }
// let obj2 = Object.assign(obj)
// obj2.username = 'wade'
// console.log(obj2)
// Array.prototype.slice和Array.prototype.concat
// slice和concat方法不修改原数组,只会返回一个浅复制了原数组元素的一个新数组
// 如果该元素是一个对象引用(而不是实际的对象),slice会拷贝这个对象用到新的数组中。
// 两个对象引用都引用了同一个对象。如果被对象引用的对象发生改变,则新的和原来的数组中的这个元素会发生改变
// 对于字符串,数字及布尔值来说(不是string,number或者boolean对象),slice会拷贝这些值到新的数组里
// 在别的数组里修改这些字符串或是布尔值,将不会影响另一个数组
// 深拷贝
//1. JSON.parse和JSON.stringify 可以实现数组或对象深拷贝,但不能处理函数。JSON.stringify()方法将一个javascript值转换为一个json字符串,而不接受一个函数
// let arr = [1, 3, {
// username: 'kobe'
// }]
// let arr4 = JSON.parse(JSON.stringify(arr))
// arr4[2].username = 'simin'
// console.log(arr, arr4)
// 2.手写递归方法
// 递归方法实现深度克隆原理: 遍历对象,数组知道里面都是基本数据类型,然后再去复制,就是深拷贝
Object.prototype.clone = function () {
var newObject = this.constructor === Array ? [] : {}
for (let e in this) {
newObject[e] = typeof this[e] === 'object' ? this[e].clone() : this[e]
}
return newObject
}
// console.log( [1, 3, {username: 'kobe'}].clone)
// 3.函数库loadsh
var _ = require('lodash');
var obj1 = {
a: 1,
b: { f: { g: 1 } },
c: [1, 2, 3]
};
var obj2 = _.cloneDeep(obj1);
console.log(obj1.b.f === obj2.b.f);
1、提高加载性能
2、提高渲染性能
// .sync 修饰符
// 在有些情况下,我们可能需要一个对prop进行'双向绑定'。不幸的是,真正的双向绑定会带来维护上的问题
// 因为子组件可以修改父组件,且在父组件和子组件都没有明显的改动来源
// 1.子组件向父组件传递参数通过事件接口实现即我们经常使用的$on(),$emit(),
// 2..sync修饰符是改变父组件的状态,当子组件与父组件公用状态的时候也会改变,可以通过重新复制的形式将父组件传递给子组件的
// 转态保存 达到只改变父组件视图的效果
// 3.$on(),$emit() 只是单独起到传递参数的作用,
可以将函数作为参数传递给其他函数,并将他们作为值返回。
高阶函数是对其他函数进行操作的函数map,filter , reduce等内置
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.