---
title: "Js 自定义回调函数"
author: "mlxnle"
date: "2012-09-03T18:46:34Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2012-09-03T18:46:34Z"
id: 1670679
url: "https://mlxnle.iteye.com/blog/1670679"
---

使用jQuery的时候发现它内部的很多方法都提供回调函数, 非常方便

 

于是萌生了自定义回调函数的冲动, 送上小例：

```
/**
 * 回调函数测试方法
 * 
 * @param callback
 *            被回调的方法
 */
function testCallback(callback) {
	alert('come in!');
	callback();
}

/**
 * 被回调的函数
 */
function a() {
	alert('a');
}

/**
 * 开始测试方法
 */
function start() {
	testCallback(a);
}
```