问面试官的问题

  • 公司做的项目中,前端主要使用的是什么框架?
  • 实习期后能不能转正?
  • 平时上下班的时间是什么时候?

模拟面试题

1. 什么是盒子模型?

css 中,盒模型分为 content、padding、border、margin四部分,又有两种盒模型,通过 box-sizing 切换:

标准盒模型

当设置为 content-box 时,属于标准盒模型,在设置宽度和高度时,只包含 content,不包含 padding 和 border;

IE盒模型(怪异模型)

而设为 border-box 时,属于 IE 盒模型,设置宽度和高度时,包含 content、padding 和 border。

2. 深克隆与浅克隆?

浅拷贝 : 只是将数据中所有的数据引用下来,依旧指向同一个存放地址,拷贝之后的数据修改之后,也会影响到原数据的中的对象数据。例如:Object.assign(),…扩展运算符
深拷贝: 将数据中所有的数据拷贝下来,对拷贝之后的数据进行修改不会影响到原数据

  1. 写一个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; }

  1. 2. JSON.parse(JSON.stringify(object))
  2. <a name="b113327e"></a>
  3. ### 深拷贝中需要注意的问题
  1. 会忽略 undefined
  2. 会忽略 symbol
  3. 不能序列化函数
  4. 不能解决循环引用的对象
  5. 不能正确处理new Date()
  6. 不能处理正则 ```

3. 什么情况下会发生布尔值的隐式强制类型转换?

(1) if (..) 语句中的条件判断表达式。
(2) for ( .. ; .. ; .. ) 语句中的条件判断表达式(第二个)。
(3) while (..) 和 do..while(..) 循环中的条件判断表达式。
(4) ? : 中的条件判断表达式。
(5) 逻辑运算符 ||(逻辑或)和 &&(逻辑与)左边的操作数(作为条件判断表达式)。

其它

手写深克隆

手写Promise

轮播图

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title></title>
  6. <style type="text/css">
  7. * {
  8. margin: 0;
  9. padding: 0;
  10. text-decoration: none;
  11. }
  12. body {
  13. padding: 20px;
  14. }
  15. #container {
  16. position: relative;
  17. width: 600px;
  18. height: 400px;
  19. border: 3px solid #333;
  20. overflow: hidden;
  21. }
  22. #list {
  23. position: absolute;
  24. z-index: 1;
  25. width: 4200px;
  26. height: 400px;
  27. }
  28. #list img {
  29. float: left;
  30. width: 600px;
  31. height: 400px;
  32. }
  33. #buttons {
  34. position: absolute;
  35. left: 250px;
  36. bottom: 20px;
  37. z-index: 2;
  38. height: 10px;
  39. width: 100px;
  40. }
  41. #buttons span {
  42. float: left;
  43. margin-right: 5px;
  44. width: 10px;
  45. height: 10px;
  46. border: 1px solid #fff;
  47. border-radius: 50%;
  48. background: #333;
  49. cursor: pointer;
  50. }
  51. #buttons .on {
  52. background: orangered;
  53. }
  54. .arrow {
  55. position: absolute;
  56. top: 180px;
  57. z-index: 2;
  58. display: none;
  59. width: 40px;
  60. height: 40px;
  61. font-size: 36px;
  62. font-weight: bold;
  63. line-height: 35px;
  64. text-align: center;
  65. color: #fff;
  66. background-color: RGBA(0, 0, 0, .3);
  67. cursor: pointer;
  68. }
  69. .arrow:hover {
  70. background-color: RGBA(0, 0, 0, .7);
  71. }
  72. #container:hover .arrow {
  73. display: block;
  74. }
  75. #prev {
  76. left: 20px;
  77. }
  78. #next {
  79. right: 20px;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <div id="container">
  85. <div id="list" style="left: -600px;">
  86. <img src="img/5.png" alt="1" />
  87. <img src="img/1.png" alt="1" />
  88. <img src="img/2.png" alt="2" />
  89. <img src="img/3.png" alt="3" />
  90. <img src="img/4.png" alt="4" />
  91. <img src="img/5.png" alt="5" />
  92. <img src="img/1.png" alt="5" />
  93. </div>
  94. <div id="buttons">
  95. <span index="1" class="on"></span>
  96. <span index="2"></span>
  97. <span index="3"></span>
  98. <span index="4"></span>
  99. <span index="5"></span>
  100. </div>
  101. <a href="javascript:;" id="prev" class="arrow"><</a>
  102. <a href="javascript:;" id="next" class="arrow">></a>
  103. </div>
  104. <script>
  105. window.onload = function() {
  106. var list = document.getElementById('list');
  107. var prev = document.getElementById('prev');
  108. var next = document.getElementById('next');
  109. function animate(offset) {
  110. /*获取的是style.left,是相对左边获取距离,所以第一张图后style.left都为负值,
  111. 且style.left获取的是字符串,需要用parseInt()取整转化为数字。*/
  112. var newLeft = parseInt(list.style.left) + offset;
  113. list.style.left = newLeft + 'px';
  114. if(newLeft < -3000) {
  115. list.style.left = -600 + 'px';
  116. }
  117. if(newLeft > -600) {
  118. list.style.left = -3000 + 'px';
  119. }
  120. }
  121. /*需要定位到按钮的样式*/
  122. var buttons = document.getElementById('buttons').getElementsByTagName('span');
  123. var index = 1;
  124. function buttonShow() {
  125. /*console.log(buttons.length);*/
  126. /*清除之前的样式*/
  127. for(var i = 0; i < buttons.length; i++) {
  128. if(buttons[i].className === 'on') {
  129. buttons[i].className = '';
  130. }
  131. }
  132. /*数组从0开始,temp从-1开始*/
  133. buttons[index - 1].className = 'on';
  134. }
  135. /*上一步*/
  136. prev.onclick = function() {
  137. index = index - 1;
  138. if(index < 1) {
  139. index = 5;
  140. }
  141. buttonShow();
  142. animate(600);
  143. }
  144. /*下一步*/
  145. next.onclick = function() {
  146. index = index + 1;
  147. if(index > 5) {
  148. index = 1;
  149. }
  150. buttonShow();
  151. animate(-600);
  152. }
  153. /*自动循环播放*/
  154. var timer;
  155. function play() {
  156. timer = setInterval(function() {
  157. next.onclick();
  158. }, 1500)
  159. }
  160. play();
  161. /*鼠标放上(离开)对应轮播暂停(播放)*/
  162. var container = document.getElementById('container');
  163. function stop() {
  164. clearInterval(timer);
  165. }
  166. container.onmouseover = stop;
  167. container.onmouseout = play;
  168. /*小圆点的点击事件*/
  169. for(var i = 0; i < buttons.length; i++) {
  170. /*使用立即函数*/
  171. (function(i) {
  172. buttons[i].onclick = function() {
  173. console.log(i);
  174. /*偏移量的获取:获取鼠标的小圆点的位置,用this把index绑定到对象buttons[i]上*/
  175. /*由于index是自定义属性,需要用到getAttribute()这个dom的2级方法,去获取自定义的index属性*/
  176. var clickIndex = parseInt(this.getAttribute('index'));
  177. var offset = 600 * (index - clickIndex);
  178. animate(offset);
  179. index = clickIndex;
  180. buttonShow();
  181. }
  182. })(i)
  183. }
  184. }
  185. </script>
  186. </body>
  187. </html>

AJAX

  1. <button id="btn">发送get请求</button>
  2. <body>
  3. <script>
  4. btn.onclick = function () {
  5. // 1、创建 AJAX 对象;
  6. var ajax = new XMLHttpRequest();
  7. // 2、设置请求路径,请求方式等;ajax.open(请求方式,路径)
  8. ajax.open('get', 'http://kumanxuan1.f3322.net:8001/index/index');
  9. // 3、绑定监听状态改变的处理函数,在处理函数可获取响应数据;
  10. ajax.onreadystatechange = function () {
  11. // console.log(ajax.readyState);
  12. if (ajax.readyState == 4 && ajax.status == 200) {
  13. // 此时获取服务器发过来的数据
  14. console.log(ajax.responseText) // 得到的是字符串对象,需要用JSON.parse(txt)转对象
  15. }
  16. }
  17. // 4、发送请求。
  18. ajax.send();
  19. }
  20. </script>
  21. </body>