美团社招一面
做题
1、面试题
<style>
.outer{width: 100px;background: red;height: 100px;
}.inner {width: 50px;height: 50px;background: green;
}</style>
<div class="outer"><div class="inner"></div>
</div><script>var outer = document.querySelector('.outer');var inner = document.querySelector('.inner');new MutationObserver(function () {console.log('mutate');}).observe(outer, {attributes: true,});function onClick(e) {console.log('click');setTimeout(function () {console.log('timeout');}, 0);Promise.resolve().then(function () {console.log('promise');});outer.setAttribute('data-random', Math.random());}inner.addEventListener('click', onClick);outer.addEventListener('click', onClick);
</script>
2、js
function Foo() {getName = function () { console.log (1); };return this;
}
Foo.getName = function () { console.log (2);};
Foo.prototype.getName = function () { console.log (3);};
var getName = function () { console.log (4);};
function getName() { console.log (5);}Foo.getName();//
getName();//
Foo().getName();//
getName();//
new Foo.getName();//
new Foo().getName();//
new new Foo().getName();//
3、
题目:
使用Vue3 / react 分别实现倒计时功能
10-0,到0时自动停止
设置3个按钮,开始 暂停 重置
解答:
注意:记得定时器使用的坑,以及取消页面挂载的时候移除定时器