I so wish that js had better support for curry for cases like this.