哈哈:)我的codepen 的代码笔记是:http://codepen.io/shinewaker/pen/eBwPxJ

-------------------------------------------------------

I mean, check it out this code :

<a href="#" id="link">Link</a>
<span>Moving</span> $('#link').click(function () {
console.log("Enter");
$('#link').animate({ width: 200 }, 2000, function() {
console.log("finished");
});
console.log("Exit");
});

as you can see in console, the "animate" function is Asynchronous, and it "fork" the flow of the event handler block code. In fact :

$('#link').click(function () {
console.log("Enter");
asyncFunct();
console.log("Exit");
}); function asyncFunct() {
console.log("finished");
}

follow the flow of the block code!

If I wish to create my function asyncFunct() { } with this behaviour, how can I do it with javascript/jquery? I think there is a strategy without use setTimeout() ​

You cannot make a truly custom asynchronous function. You'll eventually have to leverage on a technology provided natively, such as:

  • setInterval
  • setTimeout
  • requestAnimationFrame
  • XMLHttpRequest
  • WebSocket
  • Worker
  • Some HTML5 APIs such as the File API, Web Database API
  • Technologies that support onload
  • ... many others

In fact, for the animation jQuery uses setInterval.

How can I create an Asynchronous function in Javascript?的更多相关文章

  1. AsyncCalls – Asynchronous function calls

    AsyncCalls – Asynchronous function callsWith AsyncCalls you can execute multiple functions at the sa ...

  2. How to create DB2 user function easily by DB Query Analyzer 6.03

    How to create DB2user function easily by DB Query Analyzer 6.03 Ma Genfeng (Guangdong Unitoll Servic ...

  3. DeprecationWarning: Calling an asynchronous function without callback is deprecated. - how to find where the “function:” is?

    I recently updated my node to 7.2.1 and noticed that there is a warning coming: (node:4346) Deprecat ...

  4. GreenPlum学习笔记:create or replace function创建函数

    原始表数据如下: 需求:现要求按分号“;”将rate_item列进行分割后插入到新的数据表中. CREATE OR REPLACE FUNCTION fun_gp_test_xxx_20181026( ...

  5. CREATE OR REPLACE FUNCTION

    CREATE OR REPLACE FUNCTION SF_Taishou_Ksai_Date(v_receiptNum IN CHAR,                                ...

  6. 理解callback function in javascript

    以下内容主要摘自[1,2] (1)In javascript, functions are first-class objects, which means functions can be used ...

  7. Dreamweaver 扩展开发: Calling a C++ function from JavaScript

    After you understand how C-level extensibility works in Dreamweaver and its dependency on certain da ...

  8. A Few Words on Callbacks and Asynchronous Mechanism In Javascript

    It is said that the one of the most routine work a javascript programmer do is writing codes like &q ...

  9. how to disabled alert function in javascript

    how to disabled alert function in javascript alert 阻塞主线程 default alert; // ƒ alert() { [native code] ...

随机推荐

  1. Visual Studio 2010 使用 ankhsvn

    之前用的 Windows XP + Visual Studio 2010 + ankhSvn,其中ankhSvn安装完后直接可用, 后来系统换成Windows10后安装ankhSvn,Extentio ...

  2. SharePoint:备份和还原

    注意事项: 1.备份和还原最好都用PowerShell,用时候用管理中心会遇到错误. 2.备份PowerShell要注意数据库服务器名,要与管理中心的数据库服务器一致,用ip可能会报错. Restor ...

  3. AngularJS 初学笔记(理论基础)

    AngularJS 是一个 JavaScript 框架.它是一个以 JavaScript 编写的库. AngularJS 通过 ng-directives 扩展了 HTML. ng-app 指令定义一 ...

  4. git和SVN的区别

    1)Git是分布式的,SVN不是: 这 是GIT和其它非分布式的版本控制系统,例如SVN,CVS等,最核心的区别.好处是跟其他同事不会有太多的冲突,自己写的代码放在自己电脑上,一段时间后再提交.合并, ...

  5. How to fix 'sudo: no tty present and no askpass program'以及硬盘序列号的读写

    在调用system命令读写硬盘序列号的过程中遇到问题,报错如下: sudo: no tty present and no askpass program 发现此问题是由于帐号并没有开启免密码导致的 . ...

  6. C#打包时设置图标ico错误

    1:无法生成"[DesktopFolder]"中名为"用户桌面 的快捷方式"的快捷方式在生成安装项目时报错 2:在进行安装项目时候,创建快捷方式并且设置了 ic ...

  7. net之session漫谈及分布式session解决方案

    最近一直在纠结net下分布式会话的实现,现将近日来的个人感想记录如下,如果有什么更好的解决方案请指教. 1.什么是session: Session 对象存储特定用户会话所需的属性及配置信息.这样,当用 ...

  8. 【.NET】字符串处理

    类名:DealString /// 1.截取字符串,最后加3个小数点 /// 2.获得指定Url的参数的string类型值 /// 3.判断数据类型 /// 4.过滤JS标记 /// 5.获取Chec ...

  9. Unity3D 导出的apk进行混淆和加固防止反编译

    前言: 对于辛辛苦苦完成的apk程序被人轻易的反编译了,那就得不偿失了,这篇文章就是解决Unity打包出来的apk进行代码加固和混淆. 准备资料: 1:Obfuscator.zip  作用是代码混淆, ...

  10. Webform动态创建删除行及后台取值

    开发过程中经常碰到许多不确定事项,所以有时需要动态生成新的记录,如图所示,点击新增时新增一条参考记录,点击删除时则删除该记录:第一步,创建一个表格,用hidden记录当前最大行数,添加时则只需复制模板 ...