
As we all known that we can bind every function as an actionPerform to an document element by this way :
document.getElementById(domId).onclick = FunctionMethod;
It's a wonderful implements the mode bettwen in Action and Listener.
However , what should we do if we type logic frame code for document?
here is an example for you : MouseListener to do something when we apply MouseClick Action.
//Declare MouseListner Class
var MouseListener = {
//actionPerform method
actionPerform : function(){
alert("Hey , Mouse has action.");
}
}
//ActionSource
function MouseClick(listener){
if (listener.actionPerform && typeof listener.actionPerform === "function"){
listener.actionPerform();
}
}
//Test code
MouseClick(MouseListener);
/*
* output:
*window alert : Hey, Mouse has action.
*/
write by henry
--------------------------------------------------------------------------------------------------
就像我们所知道的,我们可以通过这样一个方法绑定每一个函数事件在一个dom元素上:
document.getElementById(domId).onclick = FunctionMethod;
这个方法完美的实现了动作和。
尽管如此,当我们为页面写逻辑框架代码时,我们应该怎么做?
这里有一个例子给你 :当我们触发鼠标点击事件时,鼠标做了些事情。
//声明鼠标类
var MouseListener = {
//动作触发函数
actionPerform : function(){
alert("Hey , Mouse has action.");
}
}
//事件源
function MouseClick(listener){
if (listener.actionPerform && typeof listener.actionPerform === "function"){
listener.actionPerform();
}
}
//测试函数
MouseClick(MouseListener);
/*
* 输出:
*窗口 弹出 : Hey, Mouse has action.
*/
write by henry
