Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `bind(this)` mean? [duplicate]

Tags:

People also ask

What does bind this mean JavaScript?

The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

What is the bind ()?

JavaScript Function bind() With the bind() method, an object can borrow a method from another object. The example below creates 2 objects (person and member).

How do you bind variables in JavaScript?

We use the Bind() method to call a function with the this value, this keyword refers to the same object which is currently selected . In other words, bind() method allows us to easily set which object will be bound by the this keyword when a function or method is invoked.

What is bind and apply in JavaScript?

Apply invokes the function and allows you to pass in arguments as an array. Bind returns a new function, allowing you to pass in a this array and any number of arguments.


In some part of onInit function of a controller in a SAPUI5 application there is an auto generated code like this:

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

Now my question is what does .bind(this) mean? What does it do? Is it a pure JavaScript code or it is related to SAPUI5?