I am trying bind(i.e. bind(this)) a built-in anonymous callback function on objectHow can this be done?
bind
bind(this)
object
A simplified example:
var object = { property: function() { this.id = 'abc'; // 'this' binds to the object aFunctionWithCallback(this.id, function(data) { console.log(this); // null }); } };
Similarly, you always use bind.
Get a reference to a function (for example, returns an expression of a function) and call a method on it bind.
aFunctionWithCallback(this.id, function(data) { console.log(this); }.bind(this));
Source: https://habr.com/ru/post/1546412/More articles:Capturing new downloads in Firefox Addon SDK - javascriptxamGeographicMap формирует данные SQL-сервера - c#Intercepting download links for downloading and preventing default download dialog - javascriptHow to find visible text in text form - javaI am trying to embed a twitter widget with a standard code in a cord, but somehow it creates a link instead of a widget - cordovaИзменение формы данных с длинного на широкий с конденсированными столбцами - rProgrammatically connect to a bluetooth headset from an Android application - androidAre restrictions performed before or after a custom trigger? - sqlHow to show ads in an Android application that is extracted from my own server - androidJavaScript closure on unregistered variables - javascriptAll Articles