Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call function inside itself

I have a function that I want to call again inside, after the last line finishes.

Maybe it will be more understandable if I show code.

function updateQuantity(){ 
    // further code where I change same data
    // and now I want to start function again but with remembering the input element that called it previously 
    updateQuantity(this);  // I tried it this way but it doesn't work
}

Any idea?

like image 370
cyprian Avatar asked May 12 '16 20:05

cyprian


1 Answers

The answer is simple, it is enough to use updateQuantity.call(this) inside the updateQuantity function - when we use call and add this, the function will start again and remember the input element that previously called updateQuantity.

like image 133
cyprian Avatar answered Oct 23 '22 12:10

cyprian