快手前端一面面经
1.<ul>
<li>1</li>
<li>2</li>
..
<li>100</li>
</ul>
点击显示出元素内的内容,考事件绑定addEventListener,事件委托
document.getElementsByTagName('ul')[0].addEventListener('click',function(e){ var e = e ||window.event; if(e.target.nodeName==='LI'){ console.log(e.target.innerHTML); } },false)
var btn = document.getElementsByTagName('ul')[0] btn.onclick = function(e){ var e = e ||window.event; console.log(e.target.innerHTML); }
2.输出顺序,原因
4.const arr = [1, 2, 3, 4, 5, 6]乱序输出数组
console.log(1); setTimeout(() => { console.log(2); }, 1000); new Promise((resolve) => { console.log(3); resolve(); }).then(() => { console.log(4); }); setTimeout(() => { console.log(5); }, 0); console.log(6);3.闭包,箭头函数指向,call,bind,apply
var name = '123'; var obj = { name: '456', getName: function () { function printName() { console.log(this.name) ; } printName(); } } obj.getName();
//bind printName.bind(this)(); //call printName.call(this); //apply printName.apply(this); //=> printName = ()=>{ console.log(this.name); }
function disorderly(arr){ for (let i = 1; i < arr.length; i++) { const random = Math.floor(Math.random() * (i + 1)); [arr[i], arr[random]] = [arr[random], arr[i]]; } return arr; }
5.移动端适配。
rem
#快手前端##快手##前端工程师##校招##面经#