Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day-02-异步以及定时器 #2

Open
H246802 opened this issue Nov 22, 2018 · 1 comment
Open

day-02-异步以及定时器 #2

H246802 opened this issue Nov 22, 2018 · 1 comment

Comments

@H246802
Copy link
Owner

H246802 commented Nov 22, 2018

写一个 execTime 函数,要求

  • 参数t:时间毫秒数
  • 参数callback:回调函数
function execTime(t, callback) {
  // some code
}
console.log(1)
execTime(3000, function(){
  console.log(3)
})
console.log(2)
@H246802
Copy link
Owner Author

H246802 commented Nov 22, 2018

简单使用setTimeout即可

function execTime(t, callback) {
  setTimeout(callback,t)
}
console.log(1)
console.time('test')
execTime(3000, function(){
  console.timeEnd('test')
  console.log(3)
})
console.log(2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant