I have a predefined function that I want to fire when two different events happen. The below code works fine, but is there a way to combine these to make the code more efficient?
$("select[name=some_selector]").blur(function () {
predefined_function();
});
$("a#some_link").click(function () {
predefined_function();
});
Writing Efficient Code It allows you to speed up your development time and makes your code easier to read, debug and maintain. There are a number of different ways in which you can make your code more efficient, including: Use of loops for repeated actions.
What Does Code Efficiency Mean? Code efficiency is a broad term used to depict the reliability, speed and programming methodology used in developing codes for an application. Code efficiency is directly linked with algorithmic efficiency and the speed of runtime execution for software.
You can pass function reference only. As they are working on different event
we can't combine them.
$("select[name=some_selector]").blur(predefined_function);
$("a#some_link").click(predefined_function)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With