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

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -