javascript - What's the elegant way of binding multiple elements with different event respectively using same event handler? -
I have both $ (document) and $ (window), respectively, from the 'ready' and 'resize' event Are tied. They are sharing the same event handler.
Code:
$ (window) .on ('resize', function () {shared code}); $ (Document) .ready (function () {shared code}); Instead of the above version, this is a traditional way of handling the code to make it clean and simple;
This is really very easy.
var handler = function (event) {// whatever you want to handle}; $ (Window) .on ('resize', handler); $ (Document) .ready (handler);
Comments
Post a Comment