Hai sa vorbim despre UnderscoreJS: Partea II

postat acum 8 luni de Stefanescu Mihai in categorie iNoob

In primul articol despre UnderscoreJS v-am vorbit despre ce este aceasta librarie si ce puteti face cu ea. In acest articol am sa va vorbesc despre functia each ce ne este pusa la dispozitie de librarie.

_.each: Comenzi repetitive usor de inteles

Nu cred ca exista proiect in care sa nu ai nevoie de cel putin o bucatica de cod care sa arate catusi de putin cu urmatoarea:

var mancare = ['Cotlet', 'Piept de pui', 'Clatite'];

for(var i = 0; i < mancare.length; i++) {
  console.log('mancare: ' + mancare[i]);
}

UnderscoreJS ne permite sa scriem acest lucru mult mai simplu:

var mancaruri = ['Cotlet', 'Piept de pui', 'Clatite'];

_.each(mancaruri, function(mancare, index, mancaruri) {
  console.log('mancare: ' + mancare);
});

Tare, nu? Functia  _.each() primeste 2 parametri:

  • Un array sau un obiect prin care sa itereze
  • O functie callback

Pentru fiecare element din array, _.each() va apela functia callback (in documentatie se gaseste ca si iteratee). In aceasta functie callback avem acces la 3 parametri:

  • Valoarea arrayului la iteratia curenta (mancare).
  • Numarul iteratiei curente (index).
  • Array-ul prin care iteram (mancaruri).

Dupa cum puteti observa codul este mult mai lizibil si putem accesa elementele fara sa fim nevoiti sa scriem mancaruri[i], cum am fi folosit intr-un  for.

In urmatorul articol din aceasta serie am sa va vorbesc despre modul in care putem folosi UnderscoreJS ca si template engine.

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Comentariu postate de Bedava Bonus Veren Bahis Siteleri la data de 16.02.2017
After you've claimed the 1st two bonuses then you will have the choice coming from a large collection of welcome offers. All of they're low investment bonuses so you'll be capable of choose from either claiming a ₤ 30 free bet from Betfred, ₤ 20 from SkyBet or ₤ 20 from William Hill. There are more on their email list but these are typically 3 of our own favourite welcome offers which don't cost much within the customers behalf.
Comentariu postate de bitch la data de 16.02.2017
Have you ever thought about adding a little bit more than just your articles? I mean, what you say is fundamental and all. But think about if you added some great photos or videos to give your posts more, "pop"! Your content is excellent but with images and clips, this website could undeniably be one of the most beneficial in its niche. Awesome blog!
Comentariu postate de nature sounds la data de 17.02.2017
Hello, i think that i saw you visited my weblog thus i got here to go back the want?.I'm attempting to find issues to improve my web site!I assume its ok to make use of some of your concepts!!
Comentariu postate de visit la data de 17.02.2017
However, these gardens will take a lot more time and energy to create than koi waterfalls. Cystitis happens due to the penetration of bacteria into the urethra. Then find some woodworking plans and patterns for a nice little wooden bridge for over your pond and you are done.
Comentariu postate de Fireplace la data de 18.02.2017
I have been browsing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the net will be much more useful than ever before.
Comentariu postate de psychics online la data de 18.02.2017
Thanks for this post, I am a big fan of this web site would want to be updated.
Comentariu postate de http://ww5.yourskincare.org/ la data de 18.02.2017
Unquestionably believe that which you stated. Your favorite justification seemed to be on the web the simplest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they plainly do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people can take a signal. Will probably be back to get more. Thanks
Comentariu postate de idental opiniones la data de 18.02.2017
I visit every day a few websites and information sites to read posts, however this webpage gives feature based content.
Comentariu postate de Matt la data de 19.02.2017
I for all time emailed this web site post page to all my associates, for the reason that if like to read it next my contacts will too.
Comentariu postate de pussy la data de 19.02.2017
Hi there, every time i used to check web site posts here early in the dawn, for the reason that i love to gain knowledge of more and more.
Comentariu postate de caprimulgine la data de 20.02.2017
Hi, just wanted to tell you, I liked this post. It was helpful. Keep on posting!
Comentariu postate de phoenixbailbonds la data de 20.02.2017
Wow! This blog looks exactly like my old one! It's on a totally different topic but it has pretty much the same layout and design. Excellent choice of colors!
Comentariu postate de link la data de 21.02.2017
This post provides clear idea in favor of the new visitors of blogging, that genuinely how to do blogging.
Comentariu postate de logiciel de référencement la data de 21.02.2017
GHS tools est un outil qui permet de faire du référencement internet et bien plus encore... je vous conseil de le tester gratuitement pour vous faire votre propre avis car 10€ sont offert à l'inscription. Vous pouvez aussi venir sur le forum de GHS Tools pour découvrir les astuces des membres.
Comentariu postate de scr protection la data de 21.02.2017
Thanks for finally writing about >Hai sa vorbim despre UnderscoreJS: Partea II - Invata-Programare : Tutoriale gratuite de PHP, HTML5, CSS3, jQuery si multe altele - Tutoriale gratuite de PHP, HTML5, CSS, JavaScript, jQuery, Java, C++, Python si mutle aletele
Comentariu postate de ????????????????????????? la data de 22.02.2017
Don't forget to look over the individual passing off the fake license. Starting a racket is also a nice way to make additional money because it won't cost you any coins to start it. Protandim Review - I cannot speak for the product since I've not yet tested it speak for the product.
Comentariu postate de cell phone tracker la data de 22.02.2017
If you are going for most excellent contents like myself, simply pay a visit this web page all the time as it provides quality contents, thanks
Comentariu postate de fake drivers license la data de 22.02.2017
2) When you answer a call from a person you know, or at least the person you know as per your cell phone, be cautious. The very first result is actually a website designed to install malware or to redirect the victim to a fake Facebook log in page, or in some cases, both. Protandim Review - I cannot speak for the product since I've not yet tested it speak for the product.
Comentariu postate de tour lý s?n la data de 23.02.2017
I got this website from my friend who shared with me concerning this web page and at the moment this time I am browsing this web page and reading very informative posts here.
Comentariu postate de mobile la data de 23.02.2017
Appreciating the time and effort you put into your blog and in depth information you provide. It's good to come across a blog every once in a while that isn't the same unwanted rehashed material. Great read! I've saved your site and I'm adding your RSS feeds to my Google account.
Comentariu postate de locksmith san antonio la data de 23.02.2017
I will immediately snatch your rss as I can not in finding your email subscription hyperlink or newsletter service. Do you've any? Kindly let me recognise so that I may subscribe. Thanks.
Comentariu postate de what is vigrx plus la data de 24.02.2017
Hey there! I've been following your web site for a long time noow and finally got the bravery to go ahdad and give yyou a shou ouut from Huffman Texas! Just wznted tto tell you keep up the fantastic job!
Comentariu postate de Rose la data de 24.02.2017
This is my first time pay a quick visit at here and i am truly impressed to read all at alone place. http://amieleahy849.unblog.fr/2016/12/29/pump-up-your-sales-with-these-remarkable-driving-games-tactics/