知识点

答案



  1. var function fn(a,b) {
  2. console.log('参数'ab)
  3. console.log(this)
  4. }
  5. fn(1,2)
  6. // 1.输出结果是什么?
  7. fn.call({},3,4)
  8. // 2.输出什么?
  9. fn.apply(100,[5,6])
  10. // 3.输出什么?
  11. fn.bind({},1,2)
  12. // 4.输出什么?为什么
  13. var newFn = fn.bind({},1,2)
  14. newFn()
  15. // 5.输出什么?
  16. var fn=()=>this
  17. fn()
  18. // 6.输出什么?
  19. fn.call({})
  20. // 7.输出什么?

知识点

  • 全局函数调用者是 window this指向window
  • 箭头函数 this 指向外层 定义完成之后不能修改
  • call apply bind
    • 共同点
      • 都在函数原型链上,都可以改变一个函数执行的时候内部this指向
    • 区别
      • call (this指向,参数1,参数2)
      • apply ( this指向,[参数1,参数2])
      • bind ( this指向, 参数1, 参数2)
        • 不会调用函数,只会返回一个新的函数 答案
  1. ‘参数’,1,2 window
  2. ‘参数’,3,4 {}
  3. ‘参数’,3,4 100
  4. 返回一个新的函数,bind传参但是不调用函数
  5. ‘参数’,1,2 {}
  6. window
  7. window

  1. console.log('1-script start');
  2. setTimeout(function() {
  3. console.log('2-setTimeout');
  4. }, 0);
  5. Promise.resolve().then(function() {
  6. console.log('3-promise1');
  7. }).then(function() {
  8. console.log('4-promise2');
  9. });
  10. console.log('5-script end');
  11. // 写出log的执行顺序

知识点

  • 微任务(异步任务) 宏任务(同步任务)
    • .then()后面和定时器是微任务 答案输出顺序是 15342