今日面试题
1.上上家公司具体做什么的,你在里面做了什么,开发了的app有几个模块,具体是做哪方面的?
2.react的原理?
一.虚拟DOM
1.虚拟DOM :将页面改变内容应用到虚拟DOM上,而不是直接应用在DOM上
2.当变化被应用到虚拟DOM上时,不急着去渲染界面,而仅仅是调整DOM的内部状态
3.在虚拟DOM收集到足够的改变时,再把这些变化一次性应用到真实DOM上
4.抽离了原来的渲染过程,实现了跨平台能力
二.Diff算法
1.分层求异策略,对element diff进行算法优化
2.通过相同类生成想累死树形结构,不同类生成不同树形结构的策略,对component diff进行算法优化
3.通过设置唯一的key的策略,对element diff进行算法优化
3.react核心思想?
内存维护虚拟dom(js对象),数据变化时(setState),自动更新虚拟DOM,得到一颗新树,然后Diff新老虚拟Dom树,窄带有变化的部分,得到一个Change(patch),讲这个Patch加入队列,最终批量更新这些Patch到DOM中
1.promise.then返回什么?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
<script>
let func = function () {
return new Promise((resolve, reject) => {
resolve('返回值');
});
};
let cb = function () {
return '新的值';
}
func().then(function () {
return cb();
}).then(resp => {
console.warn(resp);
console.warn('1-------------');
});
func().then(function () {
cb()
}).then(resp => {
console.warn(resp);
console.warn('2--------------');
});
func().then(cb()).then(resp => {
console.warn(resp);
console.warn('3--------------');
});
func().then(cb).then(resp => {
console.warn(resp);
console.warn('4---------------');
})
</script>
2.es6新特性?
块作用域
类
箭头函数
模板字符串
对象解构
promise
模块
Symbol
代理(proxy)
Set
函数默认参数
rest
扩展运算符
数组和对象的扩展
轮廓和圆角
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1 {
width: 200px;
height: 200px;
background-color: aqua;
box-shadow: 150px 150px 150px rgba(0, 0, 0, 0.5)
}
.box2 {
width: 200px;
height: 200px;
background-color: pink;
border-radius: 50px 100px;
border-radius: 50%;
}
</style>
</head>
<body>
<div class="box2"></div>
</body>
</html>
盒子的尺寸
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1 {
width: 100px;
height: 100px;
background-color: pink;
padding: 10px;
border: 10px solid #000;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="box1"></div>
</body>
</html>
力扣每日一题
var convert = function(s, numRows) {
if(s.length<=numRows||numRows===1){return s};
const arr=new Array(numRows).fill('');
let num=0;
let plus=true;
for(let i=0;i<s.length;i++){
arr[num]+=s[i];
if(plus){
num+=1;
}else{
num-=1;
}
if(num===0){
plus=true
}
if(num===numRows-1){
plus=false
}
}
return arr.join('');
};