Javascript: Renaming built in functions [closed]
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector()
tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
javascript renaming
closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector()
tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
javascript renaming
closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommendconst
by default rather thanlet
– CertainPerformance
Nov 16 '18 at 3:28
One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.
– ceejayoz
Nov 16 '18 at 3:30
@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meantconst
, notlet
:) Thanks for the quick reply.
– Yang K
Nov 16 '18 at 3:30
@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.
– Yang K
Nov 16 '18 at 3:31
@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.
– Carcigenicate
Nov 16 '18 at 3:57
add a comment |
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector()
tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
javascript renaming
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector()
tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
javascript renaming
javascript renaming
asked Nov 16 '18 at 3:28
Yang KYang K
678
678
closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommendconst
by default rather thanlet
– CertainPerformance
Nov 16 '18 at 3:28
One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.
– ceejayoz
Nov 16 '18 at 3:30
@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meantconst
, notlet
:) Thanks for the quick reply.
– Yang K
Nov 16 '18 at 3:30
@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.
– Yang K
Nov 16 '18 at 3:31
@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.
– Carcigenicate
Nov 16 '18 at 3:57
add a comment |
It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommendconst
by default rather thanlet
– CertainPerformance
Nov 16 '18 at 3:28
One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.
– ceejayoz
Nov 16 '18 at 3:30
@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meantconst
, notlet
:) Thanks for the quick reply.
– Yang K
Nov 16 '18 at 3:30
@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.
– Yang K
Nov 16 '18 at 3:31
@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.
– Carcigenicate
Nov 16 '18 at 3:57
It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend
const
by default rather than let
– CertainPerformance
Nov 16 '18 at 3:28
It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend
const
by default rather than let
– CertainPerformance
Nov 16 '18 at 3:28
One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.
– ceejayoz
Nov 16 '18 at 3:30
One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.
– ceejayoz
Nov 16 '18 at 3:30
@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant
const
, not let
:) Thanks for the quick reply.– Yang K
Nov 16 '18 at 3:30
@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant
const
, not let
:) Thanks for the quick reply.– Yang K
Nov 16 '18 at 3:30
@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.
– Yang K
Nov 16 '18 at 3:31
@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.
– Yang K
Nov 16 '18 at 3:31
@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.
– Carcigenicate
Nov 16 '18 at 3:57
@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.
– Carcigenicate
Nov 16 '18 at 3:57
add a comment |
1 Answer
1
active
oldest
votes
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
1
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
No problem at all!
– Ryan
Nov 16 '18 at 3:35
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
1
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
No problem at all!
– Ryan
Nov 16 '18 at 3:35
add a comment |
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
1
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
No problem at all!
– Ryan
Nov 16 '18 at 3:35
add a comment |
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
answered Nov 16 '18 at 3:31
RyanRyan
911313
911313
1
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
No problem at all!
– Ryan
Nov 16 '18 at 3:35
add a comment |
1
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
No problem at all!
– Ryan
Nov 16 '18 at 3:35
1
1
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
Thanks mate. This is exactly what I was wondering about :)
– Yang K
Nov 16 '18 at 3:34
No problem at all!
– Ryan
Nov 16 '18 at 3:35
No problem at all!
– Ryan
Nov 16 '18 at 3:35
add a comment |
It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend
const
by default rather thanlet
– CertainPerformance
Nov 16 '18 at 3:28
One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.
– ceejayoz
Nov 16 '18 at 3:30
@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant
const
, notlet
:) Thanks for the quick reply.– Yang K
Nov 16 '18 at 3:30
@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.
– Yang K
Nov 16 '18 at 3:31
@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.
– Carcigenicate
Nov 16 '18 at 3:57