JavaScript { Part 14.1 : Libraries }

JavaScript { Part 14.1 : Libraries }

Photo by
Priscilla Du Preez on
Unsplash

Utility Methods

It’s a function that helps to you the developer to perform a specific task. JavaScript have several native utility functions such as splice(), sort(), slice(), etc. These functions have in common one thing, They perform a specific task!. Let’s take, for example, a slice method returns the selected elements in an array.

Once you have tried the utility method on JavaScript, we will go through a bunch of very useful utility methods provided by a fine library called Underscore.js

Underscore.js

Is a library that provides more than a 100 utility methods, without extending any built-in objects. its very helpful library in case you want to test your code or also useful if you want to be more productive

First I’ll require the library in my code, in order to use the functions

Let’s see now some examples of this awesome library, but before that, I would like to give you some arrays and objects which is the material you see and use in the examples

Arrays for the examples

_.Each

Takes each item from the array or object and loops through it and allow you to do whatever you want with the value

We can iterate from an object too…

Remember that more and more devices are mobile now, and users are relying on 3G or 4G connections so the result could be not good for the users if you over-size JavaScript frameworks

_.Find

This is very pretty because, looks through each value in the list, and it finds the 1st value that passes the truth test. and once it finds stop there and doesn’t traverse the entire list.

If you are a junior developer you should know that Underscore.js can be used for building complex and sustainable JavaScript applications, also embrace the functional programming principles, and follow a lightweight and efficient approach for building web apps.

_.toArray

This function turns any array-like list into an array. This can come in handy because once your list is in an array you are able to use array functions to filter it down if needed.

_.keys

This is very useful, because returns the key names of an object

_.random

Instead of reinventing the wheel, I’m still using this a lot! this random tool allows the user to return a number that is random, in this case between 0–5000!

_.rest

This is great! because it will leave off the first value in the array.

Resources

So far so good, however, I will leave you two key point resources to learn in your time underscore.js once you already see already the improvement to brings to your daily code

This two key point is free, so both drive an approach to teach essential JavaScript concepts and some good practices to build sustainable applications.

In my next chapter I’ll talk more about libraries, Did you enjoy this? Give it a clap on the left so others can discover it as well or follow me if you are interested in more chapter like this.

codeburst责编内容来自:codeburst (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » JavaScript { Part 14.1 : Libraries }

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录