Skip to content

Instantly share code, notes, and snippets.

@meowsus
Created November 26, 2013 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meowsus/7651809 to your computer and use it in GitHub Desktop.
Save meowsus/7651809 to your computer and use it in GitHub Desktop.
Refactor me plz
eventListener = function (widget) {
widget.$postalCode.one('focus', function () {
applyValidationRules(widget);
});
widget.$country.on('change', function () {
applyValidationRules(widget);
});
widget.$parentForm.on('submit', function () {
applyValidationRules(widget);
});
},
@sort-gist
Copy link

Rename the function to setListeners.

@sort-gist
Copy link

That's about it.

@imbcmdth
Copy link

eventListener = function (widget) {
    function applyRules () {
        applyValidationRules(widget);
    }
    widget.$postalCode.one('focus', applyRules);
    widget.$country.on('change', applyRules);
    widget.$parentForm.on('submit', applyRules);
},

@Announcement
Copy link

eventListener=function(w){
    (function(o,f){for(k in o)f(k,o[k]);})(
    {'focus':w.$postalCode.one,'change':w.$country.on,'submit':w.$parentForm.on},
    function(k,v){v.call(k,applyValidationRules(w))});
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment