benashby
3/27/2014 - 2:25 AM

jqueryboilerplate-closure.js

Plugin.prototype = {
  init: function () {
    var instance = this;
    
    $.ajax({
      type:'get'
    }).done(function(data) {
      //Within closure scope (`this` will no longer be the function)
      instance.yourOtherFunction(data);
    });
  },
  yourOtherFunction: function (data) {
    //Back into plugin scope (`this` will be the function again)
    data.doSomethingWithMe();
}
};