Should one-line functions be avoided in jQuery/JavaScript?

So, I had a coworker complain about how I made the following code: var foo = getKendoDropdown(window.foo); var bar = getKendoDropdown(window.foo); var sna = getKendoDropdown(window.sna); var fu = getKendoDropdown(window.fu); function getKendoDropdownList(controlId) { return $('#' + controlId).data("kendoDropDownList") } He said that there's no need to make a one-line function when using jQuery, and said I should use the following instead: var foo = $('#' + window.foo).data("kendoDropDownList"); var bar = $('#' + window.bar).data("kendoDropDownList"); var sna = $('#' + window.sna).data("kendoDropDownList"); var fu = $('#' + window.fu).data("kendoDropDownList"); However, I know that if I came across the following in C#: var redFord = cars.Where(x => x.Name = "Ford").First(x => x.Colour = "Red"); var redToyota = cars.Where(x => x.Brand = "Toyota").First(x => x.Colour = "Red"); ...I would tell whoever wrote it that they should stop repeating code and put the WET code into a method: public static Car FindTheMatchingRed(this IEnumerable cars, string brand) => cars.Where(x => x.Brand == brand).First(x => x.Colour = "Red"); So, is my coworker correct? If so, why? What makes JavaScript/jQuery different such that in this case DRY does not apply? UPDATE I should make my example stronger (and closer to the JS example) by pointing out that in this case, 'red' is meaningful (just as "kendoDropDownList" is meaningful). Maybe this code is required to run for a country in which red cars are illegal. As such, the 'x.Colour = "Red"' logic changes from being accidentally repeated to being meaningfully identical. Which, in my experience/learning, is the condition for whether you want to abstract multiple bits of repeated logic.

May 5, 2025 - 13:53
 0

So, I had a coworker complain about how I made the following code:

var foo = getKendoDropdown(window.foo);
var bar = getKendoDropdown(window.foo);
var sna = getKendoDropdown(window.sna);
var fu = getKendoDropdown(window.fu);
function getKendoDropdownList(controlId) {
    return $('#' + controlId).data("kendoDropDownList")
}

He said that there's no need to make a one-line function when using jQuery, and said I should use the following instead:

var foo = $('#' + window.foo).data("kendoDropDownList");
var bar = $('#' + window.bar).data("kendoDropDownList");
var sna = $('#' + window.sna).data("kendoDropDownList");
var fu = $('#' + window.fu).data("kendoDropDownList");

However, I know that if I came across the following in C#:

var redFord = cars.Where(x => x.Name = "Ford").First(x => x.Colour = "Red");
var redToyota = cars.Where(x => x.Brand = "Toyota").First(x => x.Colour = "Red");

...I would tell whoever wrote it that they should stop repeating code and put the WET code into a method:

public static Car FindTheMatchingRed(this IEnumerable cars, string brand) =>
    cars.Where(x => x.Brand == brand).First(x => x.Colour = "Red");

So, is my coworker correct? If so, why? What makes JavaScript/jQuery different such that in this case DRY does not apply?

UPDATE

I should make my example stronger (and closer to the JS example) by pointing out that in this case, 'red' is meaningful (just as "kendoDropDownList" is meaningful). Maybe this code is required to run for a country in which red cars are illegal. As such, the 'x.Colour = "Red"' logic changes from being accidentally repeated to being meaningfully identical. Which, in my experience/learning, is the condition for whether you want to abstract multiple bits of repeated logic.