can.proxy

  • function
 

Bind a function to its context.

can.proxy(fn, context)

Parameters

  1. fn {function()}

    The function to bind to a context.

  2. context {Object}

    The context to bind the function to.

Returns

{function()}

A function that calls fn in the context of context.

can.proxy(fn, context) accepts a function and returns a new one that will always have the context from which it was called. This works similar to jQuery.proxy.

var func = can.proxy(function(one){
    return this.a + one
}, {a: "b"});

func("two") //-> "btwo"