问面试官的问题
- 公司做的项目中,前端主要使用的是什么框架?
- 实习期后能不能转正?
- 平时上下班的时间是什么时候?
模拟面试题
1. 什么是盒子模型?
css 中,盒模型分为 content、padding、border、margin四部分,又有两种盒模型,通过 box-sizing 切换:
标准盒模型
当设置为 content-box 时,属于标准盒模型,在设置宽度和高度时,只包含 content,不包含 padding 和 border;
IE盒模型(怪异模型)
而设为 border-box 时,属于 IE 盒模型,设置宽度和高度时,包含 content、padding 和 border。
2. 深克隆与浅克隆?
浅拷贝 : 只是将数据中所有的数据引用下来,依旧指向同一个存放地址,拷贝之后的数据修改之后,也会影响到原数据的中的对象数据。例如:Object.assign(),…扩展运算符
深拷贝: 将数据中所有的数据拷贝下来,对拷贝之后的数据进行修改不会影响到原数据
- 写一个deepClone函数,递归遍历数组或者对象中嵌套的每一个子数组和子对象 ```javascript
function deepClone(obj) { if(typeof obj == “object”) { var result = obj.constructor == Array ? []: {}; for(let i in obj) { result[i] = typeof obj[i] == “object” ? deepClone(obj[i]) : obj[i]; } } else { var result = obj; } return result; }
2. JSON.parse(JSON.stringify(object))<a name="b113327e"></a>### 深拷贝中需要注意的问题
- 会忽略 undefined
- 会忽略 symbol
- 不能序列化函数
- 不能解决循环引用的对象
- 不能正确处理new Date()
- 不能处理正则 ```
3. 什么情况下会发生布尔值的隐式强制类型转换?
(1) if (..) 语句中的条件判断表达式。
(2) for ( .. ; .. ; .. ) 语句中的条件判断表达式(第二个)。
(3) while (..) 和 do..while(..) 循环中的条件判断表达式。
(4) ? : 中的条件判断表达式。
(5) 逻辑运算符 ||(逻辑或)和 &&(逻辑与)左边的操作数(作为条件判断表达式)。
其它
手写深克隆
手写Promise
轮播图
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">* {margin: 0;padding: 0;text-decoration: none;}body {padding: 20px;}#container {position: relative;width: 600px;height: 400px;border: 3px solid #333;overflow: hidden;}#list {position: absolute;z-index: 1;width: 4200px;height: 400px;}#list img {float: left;width: 600px;height: 400px;}#buttons {position: absolute;left: 250px;bottom: 20px;z-index: 2;height: 10px;width: 100px;}#buttons span {float: left;margin-right: 5px;width: 10px;height: 10px;border: 1px solid #fff;border-radius: 50%;background: #333;cursor: pointer;}#buttons .on {background: orangered;}.arrow {position: absolute;top: 180px;z-index: 2;display: none;width: 40px;height: 40px;font-size: 36px;font-weight: bold;line-height: 35px;text-align: center;color: #fff;background-color: RGBA(0, 0, 0, .3);cursor: pointer;}.arrow:hover {background-color: RGBA(0, 0, 0, .7);}#container:hover .arrow {display: block;}#prev {left: 20px;}#next {right: 20px;}</style></head><body><div id="container"><div id="list" style="left: -600px;"><img src="img/5.png" alt="1" /><img src="img/1.png" alt="1" /><img src="img/2.png" alt="2" /><img src="img/3.png" alt="3" /><img src="img/4.png" alt="4" /><img src="img/5.png" alt="5" /><img src="img/1.png" alt="5" /></div><div id="buttons"><span index="1" class="on"></span><span index="2"></span><span index="3"></span><span index="4"></span><span index="5"></span></div><a href="javascript:;" id="prev" class="arrow"><</a><a href="javascript:;" id="next" class="arrow">></a></div><script>window.onload = function() {var list = document.getElementById('list');var prev = document.getElementById('prev');var next = document.getElementById('next');function animate(offset) {/*获取的是style.left,是相对左边获取距离,所以第一张图后style.left都为负值,且style.left获取的是字符串,需要用parseInt()取整转化为数字。*/var newLeft = parseInt(list.style.left) + offset;list.style.left = newLeft + 'px';if(newLeft < -3000) {list.style.left = -600 + 'px';}if(newLeft > -600) {list.style.left = -3000 + 'px';}}/*需要定位到按钮的样式*/var buttons = document.getElementById('buttons').getElementsByTagName('span');var index = 1;function buttonShow() {/*console.log(buttons.length);*//*清除之前的样式*/for(var i = 0; i < buttons.length; i++) {if(buttons[i].className === 'on') {buttons[i].className = '';}}/*数组从0开始,temp从-1开始*/buttons[index - 1].className = 'on';}/*上一步*/prev.onclick = function() {index = index - 1;if(index < 1) {index = 5;}buttonShow();animate(600);}/*下一步*/next.onclick = function() {index = index + 1;if(index > 5) {index = 1;}buttonShow();animate(-600);}/*自动循环播放*/var timer;function play() {timer = setInterval(function() {next.onclick();}, 1500)}play();/*鼠标放上(离开)对应轮播暂停(播放)*/var container = document.getElementById('container');function stop() {clearInterval(timer);}container.onmouseover = stop;container.onmouseout = play;/*小圆点的点击事件*/for(var i = 0; i < buttons.length; i++) {/*使用立即函数*/(function(i) {buttons[i].onclick = function() {console.log(i);/*偏移量的获取:获取鼠标的小圆点的位置,用this把index绑定到对象buttons[i]上*//*由于index是自定义属性,需要用到getAttribute()这个dom的2级方法,去获取自定义的index属性*/var clickIndex = parseInt(this.getAttribute('index'));var offset = 600 * (index - clickIndex);animate(offset);index = clickIndex;buttonShow();}})(i)}}</script></body></html>
AJAX
<button id="btn">发送get请求</button><body><script>btn.onclick = function () {// 1、创建 AJAX 对象;var ajax = new XMLHttpRequest();// 2、设置请求路径,请求方式等;ajax.open(请求方式,路径)ajax.open('get', 'http://kumanxuan1.f3322.net:8001/index/index');// 3、绑定监听状态改变的处理函数,在处理函数可获取响应数据;ajax.onreadystatechange = function () {// console.log(ajax.readyState);if (ajax.readyState == 4 && ajax.status == 200) {// 此时获取服务器发过来的数据console.log(ajax.responseText) // 得到的是字符串对象,需要用JSON.parse(txt)转对象}}// 4、发送请求。ajax.send();}</script></body>
