General
- What JS libraries have you used?
- Why that over X?
- What JS tempting libraries have you used?
- How do you organize your code?
- Have you used CoffeeScript?
- What do you like/dislike about it?
- Advantages/Disadvantages over JavaScript?
General
| function formatNumber(num) { | |
| var thousands = ','; | |
| var decimal = '.'; | |
| var numStr = '' + num; | |
| var formatted = ''; | |
| if (typeof num !== 'number') { | |
| throw new Error('Must pass a number, received "' + num + '" instead.'); | |
| } |
#What is a compose method? Compose takes a series of single parameter functions that are used as the parameters for the previous functions. The last function can take any number of parameters.
Code example:
function text(a) {
return 'item: ' + a;
}
function hello(a) {
return 'Hello ' + a;
#What is the difference between Curry and Partial? This seems like a confusing topic for a lot of people. I actually had a really hard time trying to understand the difference between the two. A lot of people think they are the same thing, or that currying is just a special form of partial application.
##So what is currying? When you curry a function, it returns a function that calls another function for every parameter. Currying creates a series of single parameter functions. Some code examples should clear this up.
Underscore supports partials with _.bind(), the only downside is that you have to always pass this. So I wanted to see how hard it would be to create my own version of partial.
This is of course a silly exercise, ECMAScript 5th Edition provides a fun.bind() method that _.bind() will use that if you have at least IE 9. I just find always passing the this parameter ugly and from my understanding of functional programming you shouldn't be using this in a partial anyways.
##Here is my first attempt.
var partial = function(){ var args = Array.prototype.slice.call(arguments), fn = args.shift(); return function(){ return fn.apply(fn, args.concat(Array.prototype.slice.call(arguments) )); }}
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| Version 2, December 2004 | |
| Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
| Everyone is permitted to copy and distribute verbatim or modified | |
| copies of this license document, and changing it is allowed as long | |
| as the name is changed. | |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |