<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>setTimeout模仿setInterval</title> </head> <body> <script> function newInterval(func, delay) { function inside(a) { func(a); setTimeout(inside, delay, 5); } setTimeout(inside, delay, 5); } newInterval(like, 1000); function likc(a) { console.log(a); } </script> </body> </html>