Giter Club home page Giter Club logo

Comments (5)

Wxh16144 avatar Wxh16144 commented on July 24, 2024 4
const printNumber = number => {
    console.log(number--);
    number && setTimeout(() => printNumber(number), 1000);
};
printNumber(5);

from fe-practice-hard.

liwenkang avatar liwenkang commented on July 24, 2024 2
// 利用了 let
const printNumber = () => {
    for (let i = 5; i > 0; i--) {
        setTimeout(() => {
            console.log(i)
        }, (6 - i) * 1000)
    }
}

// 利用了闭包
const printNumber = () => {
    for (var i = 5; i > 0; i--) {
        (function (i) {
            setTimeout(() => {
                console.log(i)
            }, (6 - i) * 1000)
        })(i)
    }
}

// 利用了闭包
const printNumber = () => {
    for (var i = 5; i > 0; i--) {
        setTimeout(((i) => {
            return () => {
                console.log(i);
            }
        })(i), (6 - i) * 1000);
    }
}

from fe-practice-hard.

cnyballk avatar cnyballk commented on July 24, 2024 1
const outputNumber = () => {
  const max = 5;
  let i = max;
  while (i) {
    setTimeout(i => {
      console.log(max + 1 - i);
    },1000 * i, i--);
  }
};

from fe-practice-hard.

AMY-Y avatar AMY-Y commented on July 24, 2024
//setTimeout循环和条件停止循环
//参考网址:https://blog.csdn.net/qq_28256783/article/details/80097092
var a=6;
function printN(){
   if(a>1){
     a=a-1;
     console.log(a);
     setTimeout("printN()",1000)
   }
}
printN();

from fe-practice-hard.

wingmeng avatar wingmeng commented on July 24, 2024
const printNumber = number => {
    console.log(number--);
    number && setTimeout(() => printNumber(number), 1000);
};
printNumber(5);

好优雅的代码 👍 ,不过第一个数字是直接打印出来的,根据题意,所有的数字都应该隔1s才打印

from fe-practice-hard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.