Function Atom feed

Prototype takes issue with only one aspect of functions: binding.

What is binding?

“Binding” basically determines the meaning, when a function runs, of the this keyword. While there usually is a proper default binding (this refers to whichever object the method is called on), this can be “lost” sometimes, for instance when passing a function reference as an argument.

If you don’t know much about the this keyword in JavaScript, hop to the docs for the bind() method. The examples there will clear it up.

Prototype to the rescue!

Prototype solves this. You’ll find two new methods on any function: one that guarantees binding (it can even guarantee early parameters!), and one that is specific to functions intended as event handlers.



someFunction.argumentNames() -> Array

Reads the argument names as defined in the function definition and returns the values as an array of strings, or an empty array if the function is defined without parameters.


bind(thisObj[, arg...]) -> Function

Wraps the function in another, locking its execution scope to an object specified by thisObj.


bindAsEventListener(thisObj[, arg...]) -> Function

An event-specific variant of bind which makes sure the function will recieve the current event object as the first argument when executing.


  curry(arg...) -> Function

Partially applies the function, returning a function with one or more arguments already “filled in.”


defer(arg...) -> Number

Schedules the function to run as soon as the interpreter is idle.


delay(seconds[, arg...]) -> Number

Schedules the function to run after the specified amount of time, passing any arguments given.


someFunction.methodize() -> Function

Takes a function and wraps it in another function that, at call time, pushes this to the original function as the first argument.


wrap(wrapperFunction[, arg...]) -> Function

Returns a function “wrapped” around the original function.