Tagged Questions
44
votes
4answers
27k views
How to use underscore.js as a template engine?
I'm trying to learn about new usages of javascript as a serverside language and as a functional language. Few days ago I heard about node.js and express framework. Then I saw about underscore.js as a ...
39
votes
8answers
7k views
Javascript as a functional language
I am looking get to grips with functional programming concepts.
I've used Javascript for many years for client side scripting in web applications and apart from using prototypes it was all simple DOM ...
38
votes
11answers
7k views
How to avoid long nesting of asynchronous functions in Node.js
I want to make a page that displays some data from a DB, so I have created some functions that get that data from my DB. I'm just a newbie in Node.js, so as far as I understand, if I want to use all ...
31
votes
10answers
6k views
Is Javascript a Functional Programming Language?
Just because functions are first class objects, there are closures, and higher order functions, does Javascript deserve to be called a Functional Programming language? The main thing I think it lacks ...
27
votes
4answers
3k views
Are any Javascript engines tail call optimized?
I have a tail recursive pathfinding algorithm that I've implemented in Javascript and would like to know if any (all?) browsers would possibly get stack overflow exceptions.
22
votes
7answers
3k views
Javascript equivalent of Python's zip function
Is there a javascript equivalent of Python's zip function? That is, given two arrays of equal lengths create an array of pairs.
20
votes
4answers
8k views
How can I pre-set arguments in JavaScript function call? (Partial Function Application)
I am trying to write a JavaScript function that will return its first argument(function) with all the rest of its arguments as preset parameters to that function.
So:
function out(a, b) {
...
17
votes
4answers
349 views
If functions in JS are first-class, what allows them to be called before they are defined?
Don't first class functions mean that they behave as variables? Clearly they don't behave exactly like variables though, since this:
console.log(foo);
var foo = 'bar';
...doesn't work, whereas ...
15
votes
4answers
2k views
How is a functional programming-based JavaScript app laid out?
I've been working with node.js for a while on a chat app (I know, very original, but I figured it'd be a good learning project). Underscore.js provides a lot of functional programming concepts which ...
14
votes
2answers
10k views
underscore.js _.each(list, iterator, [context]) what is context?
New to underscore.js. I am pretty much looking for an example on how to use [context]/[context] inside the iterator.
14
votes
5answers
544 views
n-ary curry in CoffeeScript
I was playing with CoffeeScript when I found myself writing the following lines and then looking at them in awe:
compose = (f, g) -> (x) -> f g x
curry = (f) -> (x) -> (y) -> f(x, y)
...
13
votes
6answers
3k views
reinventing the wheels: Node.JS/Event-driven programming v.s. Functional Programming?
Now there's all the hype lately about Node.JS, an event driven framework using Javascript callbacks. To my limited understanding, its primary advantage seems to be that you don't have to wait step by ...
13
votes
1answer
784 views
Is this a monad?
I'm trying to understand the concept of monads and I want to know if this code is an implementation of this concept (in JavaScript).
I have function M which return new object that have set method ...
12
votes
2answers
846 views
Get a function's arity
In Javascript, how can one determine the number of formal parameters defined for a function?
Note, this is not the arguments parameter when the function is called, but the number of named arguments ...
11
votes
1answer
271 views
Is it possible to implement a js version of Haskell's unzip in a purely functional fashion?
I'm implementing a javascript ray-casting point-in-polygon algorithm in a purely functional fashion (no particular reason behind it).
I got stuck as i needed to get two arrays from a 2-dimentional ...