本文介绍了如何在内部调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,我希望在最后一行结束后在内部再次调用.

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
}

有什么主意吗?

推荐答案

答案很简单,在updateQuantity函数中使用updateQuantity.call(this)就足够了-当我们使用call并添加this时,函数将再次启动,并记住先前称为updateQuantity的输入元素.

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.

这篇关于如何在内部调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 12:53