function.bind() code example

Example 1: bind (this)

this.getView().addEventDelegate({
            onBeforeFirstShow: function() {
                // Some codes
            }.bind(this)
        });

Example 2: javascript bind

function myFunc(p1, p2, pN, addedParam)
{
     // here "this" equals "myThis"
}
let myThis = {};

// create new function that, when invoked, calls
// myFunc using myThis as context.
// prepend params as function arguments to those
// provided when invoked.
let f = myFunc.bind(myThis, "param1", "param2", "paramN");
f("addedParam");

Tags:

Php Example