Javascript: Renaming built in functions [closed]

廉价感情. 提交于 2021-01-29 14:28:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53330996/javascript-renaming-built-in-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!