JavaScript 函数闭包实现多个事件的监听

function AddEvent(obj, evt, fn)

{

  var saved;

     if(typeof obj[“on" + evt] == " function") 

     {  

    saved = ojb["on" + evt];

  }

     obj["on" + evt] = function()

  {

    if(saved)

      saved();

    fn();

  }

}

 

 

var functions =[];

function addEvent(obj , evt, fns)

{

  functions.push(fn);

  if(typeof obj ["on" + evt] == "function")

  {

    functions.push(obj["on" + evt]);

  }

  obj["on" + evt] = function()

  {

    for(var i = 0; i< functions.length; i++)

    {

      functions[i].call(this);

    }

  }

}

posted @ 2011-09-14 21:53  Space Tian  阅读(386)  评论(0编辑  收藏  举报