jPaq Example - Currying Up String Functions

You ever wonder how libraries such as jPaq and Prototype add prototype functions to different classes?  At for jPaq, it isn't by relying on the curry function.  Perhaps it should be though.  The following example shows that you can use the curry function to produce trim, trimLeft, trimRight, addSlashes, and surroundWith, each with just one line of code.  In the example, I also added two casing functions with minimal effort to the string prototype.  Execute the code below and see the result of running these functions:

Applicable Parts

Related Examples

  1. Currying
    At times, you may want to call a function a number of times, but you may notice that the first few arguments are always the…
  2. Flatten Arrays
    One of the nice functions that is provided in Prototype is Array.prototype.flatten().  It gives you the ability to turn arrays such as…
  3. Compacting Arrays
    The JavaScript library Prototype offers a function which basically removes all of the undefined and null values from the array. Fortunately, JavaScript 1.6 offers…