Quantcast
Channel: User Filip Milovanović - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 182

Comment by Filip Milovanović on Is a callback function with `this` as an argument a bad practice?

$
0
0
With option 2, you must have an existing instance of Foo that you can lambda-capture. If your class Bar had fields foo and foo1, and you used the wrong one (say, by copy-pasting the code and forgetting to edit it), would that cause a problem? With option 1, you can write the callback anywhere in the code, without having an instance, and you have control over what is passed in as the Foo parameter, and when. The lambda capture is fine for ad hoc stuff; here, since "the user of the class instance is expected to do stuff on the instance itself", option 1 is a more natural way to model that.

Viewing all articles
Browse latest Browse all 182

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>