Get the BX24.proxy Function
Choose a tool for developing with an AI agent:
- use Alaio Vibecode to build an app for Bitrix24 from a task description without knowing any programming language. The agent writes the code and deploys the app to a server, with no manual hosting setup
- use the MCP server to develop a REST API integration in your own project. The agent refers to the official REST documentation
BX24.proxy(func: callable, thisObject: object): callable;
The BX24.proxy method creates a proxy function. The proxy function calls func, and inside func, this refers to the thisObject object. This is needed when an object method is assigned as an event handler: without a proxy, this in the handler refers to the page element, not to the object.
The method is similar in purpose to Function.prototype.bind, but for the same pair of func and thisObject it always returns the same function. That is why a handler assigned through a proxy can be removed: BX24.unbind receives the same function as BX24.bind.
The method works on an application page where the BX24.js library is connected and does not call Bitrix24, so there is no need to wait for BX24.init. The method requires no scope of its own.
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
func* |
The original function: declared with |
|
thisObject* |
The object that |
Code Example
How to Use Examples in Documentation
Assign an object method as the button handler and remove it after the third click:
<button id="counter">Click</button>
<script>
BX24.ready(function () {
const counter = {
clicks: 0,
onClick: function () {
this.clicks++;
console.log('Clicks:', this.clicks);
if (this.clicks === 3) {
BX24.unbind(button, 'click', BX24.proxy(this.onClick, this));
}
}
};
const button = document.getElementById('counter');
BX24.bind(button, 'click', BX24.proxy(counter.onClick, counter));
});
</script>
Response Handling
The method synchronously returns a result of type function. The proxy function passes all of its arguments to func and returns the result of func.
Returned Data
|
Name |
Description |
|
result |
A proxy function that calls |
A repeated call with the same pair of func and thisObject returns the same function:
const counter = { onClick: function () {} };
BX24.proxy(counter.onClick, counter) === BX24.proxy(counter.onClick, counter); // true
Error Handling
The method does not return error codes.
|
Situation |
What Happens |
What to Do |
|
|
The method returns |
Pass both parameters |
|
A non-empty string is passed in |
The method throws a |
Pass a function |
|
An object rather than a function is passed in |
The method returns a proxy function, but a |
Pass a function |
|
Something other than an object is passed in |
The method throws a |
Pass an object |
|
|
The method returns the proxy function of the parent object: |
Pass an object created without inheriting from an object that has already been passed |
|
|
The method throws a |
Pass a regular object and function |
|
An exception occurs inside |
The exception propagates out of the proxy function. After that, BX24.proxyContext may return the context of the interrupted call |
Catch exceptions inside |