Passing function as an argument

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
Rating: 8
Joined: May 21, 2023
Company:

Is it possible in 1C to pass a function as an argument to some procedure or another function?

 
#2
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Mar 10, 2017
Company: Rufinor

Peter, Hello!

Yes, this is possible. Just do it and you will see it works!

Kind regards,
Alex

 
#3
People who like this:0Yes/0No
Active user
Rating: 8
Joined: May 21, 2023
Company:

What do I pass as an argument - just function name? Do I need to put something before the function name?

 
#4
People who like this:0Yes/0No
Active user
Rating: 8
Joined: May 21, 2023
Company:

I get an error "Variable is not defined" if I pass function name as an argument for another function

 
#5
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Mar 10, 2017
Company: Rufinor

You need to pass full function inlcuding ()

yourfunction(myfunction())

 
#6
People who like this:0Yes/0No
Active user
Rating: 8
Joined: May 21, 2023
Company:

I think you didn't get my question. I need to pass as an argument only function, not the result of function execution.

 
#7
People who like this:0Yes/0No
Administrator
Rating: 33
Joined: Oct 3, 2019
Company:

Quote
Is it possible in 1C to pass a function as an argument to some procedure or another function?

Hello Peter,

do you mean passing a function as an argument to another function? Like in Javascript, for example?

No, unfortunately this is not possible. Functions in 1C are not "first class" objects (https://en.wikipedia.org/wiki/First-class_citizen), so they cannot be passed as parameters.

 
#8
People who like this:0Yes/0No
Active user
Rating: 8
Joined: May 21, 2023
Company:

Yes, I need something like passing arguments in JavaScript, PHP, Java

 
#9
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Mar 10, 2017
Company: Rufinor

1С language is designed differently from JavaScript, PHP and Java. In fact for practical reasons it does not need passing function as an argument. I also knew that Java didn't have this option for a long time until Java 8. You can do any functionality in 1c without this feature. If you share with us the reason of why you need passing function as an argument we can advise you how the task can be achieved in 1C without this.

Kind regards,
Alex

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.