Prototype JavaScript framework

class Function

Instance methods

  • argumentNames

    Function#argumentNames() -> Array

    Reads the argument names as stated 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

    Function#bind(object[, args...]) -> Function
    • object (Object) – The object to bind to.

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

  • bindAsEventListener

    Function#bindAsEventListener(object[, args...]) -> Function
    • object (Object) – The object to bind to.

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

  • curry

    Function#curry(args...) -> Function

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

    Function#curry works just like Function#bind without the initial scope argument. Use the latter if you need to partially apply a function and modify its execution scope at the same time.

  • defer

    Function#defer(args...) -> Number

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

    A “deferred” function will not run immediately; rather, it will run as soon as the interpreter’s call stack is empty.

    Behaves much like window.setTimeout with a delay set to 0. Returns an ID that can be used to clear the timeout with window.clearTimeout before it runs.

  • delay

    Function#delay(seconds[, args...]) -> Number
    • seconds (Number) – How long to wait before calling the function.

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

    Behaves much like window.setTimeout. Returns an integer ID that can be used to clear the timeout with window.clearTimeout before it runs.

    To schedule a function to run as soon as the interpreter is idle, use Function#defer.

  • methodize

    Function#methodize() -> Function

    Wraps the function inside another function that, at call time, pushes this to the original function as the first argument.

    Used to define both a generic method and an instance method.

  • wrap

    Function#wrap(wrapperFunction) -> Function
    • wrapperFunction (Function) – The function to act as a wrapper.

    Returns a function “wrapped” around the original function.

    Function#wrap distills the essence of aspect-oriented programming into a single method, letting you easily build on existing functions by specifying before and after behavior, transforming the return value, or even preventing the original function from being called.