---
title: "Ext事件机制"
author: "lixw"
date: "2009-02-19T14:41:41Z"
tags: []
slug: "ext"
draft: false
lastmod: "2009-02-19T14:41:41Z"
id: 335463
url: "https://samueli.iteye.com/blog/335463"
---

先看看这里的说明：[http://www.cnblogs.com/beginor/archive/2008/03/07/1095887.html](http://www.cnblogs.com/beginor/archive/2008/03/07/1095887.html)

 

测试代码：

 

```
Employee = function(name) {
	this.name = name;
	this.addEvents({
				"confirm" : true,
				"quit" : true
			});

	this.confirmBeforeQuit();
};

Ext.extend(Employee, Ext.util.Observable, {
			confirmBeforeQuit : function() {
				this.on("quit", function(emp) {
							this.fireEvent('confirm', this);
							return false;
						});
			}
		});

function quitHandler(emp) {
	alert(emp.name + " 安全退出");
}
function confirmHandler(emp, eve) {
	alert(emp.name + " 确认退出吗？");
}

var emp = new Employee('Tom');

emp.on('quit', quitHandler);
emp.on('confirm', confirmHandler);

emp.fireEvent("quit", emp);
```