Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiently writing functions

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();
});
like image 457
jonbaldie Avatar asked Jun 02 '15 19:06

jonbaldie


People also ask

Why do we write efficient code?

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 efficient coding mean?

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.


1 Answers

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)
like image 84
Satpal Avatar answered Sep 29 '22 09:09

Satpal