.hide(“slow”) is synchronous or Asynchronous method?

混江龙づ霸主 提交于 2019-12-02 13:02:06

.hide(“slow”) is synchronous or Asyncronous method

The call to the method is synchronous, but it starts an asynchronous process. So we would normally, loosely, call it an "asynchronous method" (in this case, where you're giving it a duration argument).

When you call hide("slow"), you synchronously tell jQuery to start the process of of hiding the element slowly over time. The process of actually doing that takes place asynchronously, after the initial call to hide is complete. (This is also true of ajax: The method itself is synchronous, but the process it starts — doing the XMLHttpRequest — continues asynchronously.)

Typically if the work of the method is completed during the call to it, we call it a synchronous method, but if it only starts work that completes later, we call it an asynchronous method. Technically the method itself isn't asynchronous, just the overall process that it initiates, but...

hide itself, of course, is both a synchronous and asynchronous method depending on what argument(s) you pass it: If you call it with no duration (.hide()), it's synchronous; if you call it with a duration (.hide("slow"), .hide(400)), it's asynchronous.

Also, for your another question,

I am very confused about this Synchronous Asynchronous concept Can someone help me to understand this concept ?

When you debug a line of code and the line is not passing to the next line until the execution completes, its synchronous operation since the same thread is performing the complete execution of the code.

On the other hand, if debugging is passing to the next line before the actual operation completes then its asynchronous operation since as in your question above, the hide & animation are performed in the background with different thread while the main thread started executing the next line.

Hope it clarifies your question above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!