• function

can.unbind

 

Stop listening for events on an object.

can.unbind.call(target, eventName, handler)

Parameters

  1. target {Object}

    The object that emits events.

  2. eventName {String}

    The name of the event to listen for.

  3. handler {function()}

    The function to unbind.

Returns

{Object}

The target.

can.unbind(eventName, handler) unbinds a callback handler from an object for a given event. It works on:

  • HTML elements and the window
  • Objects
  • Objects with bind / unbind methods

The idea is that unbind can be used on anything that produces events and it will figure out the appropriate way to unbind to it. Typically, can.unbind is only used internally to CanJS; however, if you are making libraries or extensions, use can.bind to listen to events independent of the underlying library.

Binding/unbinding to an object

var obj = {},
handler = function(ev, arg1, arg){
       arg1 // 1
       arg2 // 2
     };
can.bind.call(obj,"something", handler)
can.trigger(obj,"something",[1,2])
can.unbind.call(obj,"something", handler)

Binding/unbinding to an HTMLElement

var el = document.getElementById('foo'),
handler = function(ev){
       this // el
     };
can.bind.call(el, "click", handler)
can.unbind.call(el, "click", handler)