开发者

JavaScript: Is there a utils library? [closed]

开发者 https://www.devze.com 2023-02-05 00:57 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

I'm wondering if such a library exists, where the library contains only a collection of common utility functions such as trim, indexOf (for arrays), map, each, typeOf and so on...

I'm aware that jQuery provides some of the functions I listed above, but I'm looking for something that is designed purely for thi开发者_开发百科s (I really don't need jQuery on the server-side running node.js for instance, nor do I want to depend on it if I'm writing a non-jQuery-related JavaScript library). I've recently begun collecting an assortment of these functions for future copy/pasting, but my guess is that there are many others that I won't even know to look for, or think of using, unless someone presents them to me.


I'm fond of underscore.js; it doesn't provide string utilities such as trim; it's focused on object-oriented and functional utilities, including all of the other things you mention. Another nice thing about it is that it doesn't reference the DOM at all, so it's useful for javascript programming that isn't web-based or DOM related.


The functions you mention are all standard in ECMAScript 5. And this library implements them in such a way that you can use them in older browsers/JavaScript versions as well, in a way that will be compatible when your environment catches up with the standard:

https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js


Boiler.js is an up and coming utility library that offers many useful JavaScript utilities and is a direct competitor with Underscore.js.


jQuery provides all of those and many more, you would be better off just using it.

jQuery can sit side-by-side with other frameworks, so can be independent if another framework is present.

See: jQuery Utilities Documentation


Javascript itself has many of these functions built into the basic types. Before building your own, perhaps a copy of JavaScript: The Definitive Guide, focusing on the API reference in the back, would do you some solid good.

After that investigate frameworks, or at least being looking into how you can create your own framework for your functions (as opposed to copying and pasting). Here the module pattern would be helpful to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号