Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

callback hell

let order = (call_production) => {
  setTimeout(() => {    
    call_production();
  }, 1000);
};
let production = () => {
  setTimeout(() => {
    console.log("step 1");
    setTimeout(() => {
      console.log("step 2");
      setTimeout(() => {
        console.log("step 3");
        setTimeout(() => {
          console.log("step 4");
          setTimeout(() => {
            console.log("step 5");
            setTimeout(() => {
              console.log("step 6");
              setTimeout(() => {
                console.log("step 7");
                setTimeout(() => {
                  console.log("step 8");
                  setTimeout(() => {
                    console.log("step 9");
                    setTimeout(() => {
                      console.log("step 10");
                      setTimeout(() => {
                        console.log("A call backhell");
                      }, 1000);
                    }, 1000);
                  }, 1000);
                }, 1000);
              }, 1000);
            }, 1000);
          }, 1000);
        }, 1000);
      }, 1000);
    }, 1000);
  }, 1000);
};
order(production);
Comment

callback hell

The cause of callback hell is when people try to write JavaScript in a way where execution happens visually from top to bottom.
Lots of people make this mistake! 
In other languages like C, Ruby or Python there is the expectation that whatever happens on line 1 will finish before the code on line 2 starts running and so on down the file.
As you will learn, JavaScript is different.

Comment

callback hell

fs.readdir(source, function (err, files) {
  if (err) {
    console.log('Error finding files: ' + err)
  } else {
    files.forEach(function (filename, fileIndex) {
      console.log(filename)
      gm(source + filename).size(function (err, values) {
        if (err) {
          console.log('Error identifying file size: ' + err)
        } else {
          console.log(filename + ' : ' + values)
          aspect = (values.width / values.height)
          widths.forEach(function (width, widthIndex) {
            height = Math.round(width / aspect)
            console.log('resizing ' + filename + 'to ' + height + 'x' + height)
            this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) {
              if (err) console.log('Error writing file: ' + err)
            })
          }.bind(this))
        }
      })
    })
  }
})
Comment

CallBack Hell

let production = () =>{

  setTimeout(()=>{
    console.log("production has started")
    setTimeout(()=>{
      console.log("The fruit has been chopped")
      setTimeout(()=>{
        console.log(`${stocks.liquid[0]} and ${stocks.liquid[1]} Added`)
        setTimeout(()=>{
          console.log("start the machine")
          setTimeout(()=>{
            console.log(`Ice cream placed on ${stocks.holder[1]}`)
            setTimeout(()=>{
              console.log(`${stocks.toppings[0]} as toppings`)
              setTimeout(()=>{
                console.log("serve Ice cream")
              },2000)
            },3000)
          },2000)
        },1000)
      },1000)
    },2000)
  },0000)

};
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to create a blob javascript 
Javascript :: testing jest 
Javascript :: nodemon 
Javascript :: Add New Properties to a JavaScript Object 
Javascript :: difference 
Javascript :: change color in react 
Javascript :: duplicate images in webpage js 
Javascript :: javascript encrypt decrypt 
Javascript :: Jquery check if hover over child element 
Javascript :: dart how to convert json to x-www-form-urlencoded 
Javascript :: JavaScript switch With Multiple Case 
Javascript :: how to give data from react native to webview 
Javascript :: get two types of date formate datepicker 
Javascript :: react router link electron not working 
Javascript :: react catch error json message 
Javascript :: ERROR TypeError: By.Subject is not a constructor 
Javascript :: custom css mui 
Javascript :: esbuild 
Javascript :: package.json merger 
Javascript :: javascript math 
Javascript :: javascript Iterate Through Iterables 
Javascript :: send embed with webhook in JS 
Javascript :: react native full screen view video player 
Javascript :: How to Check for an Empty String in JavaScript by String Comparison 
Javascript :: dm discord.js 
Javascript :: script defer attribute 
Javascript :: slice in javascript 
Javascript :: node check text include in file 
Javascript :: angular firebase 
Javascript :: change bg-color all class 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =