index.html 638 B

12345678910111213141516171819202122232425262728
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script src="./src/bind.js"></script>
  11. <script>
  12. function add (a,b){
  13. console.log(this)
  14. return a + b + this.c
  15. }
  16. let obj = {
  17. c: 5
  18. }
  19. window.c = 6
  20. //两种
  21. let fn = bind(add,obj,1,2)
  22. console.log(fn())
  23. let fn2 = bind(add,obj)
  24. console.log(fn2(1,2))
  25. </script>
  26. </body>
  27. </html>