JavaScript Callback Scope [duplicate]

This question already has answers here: How to access the correct `this` inside a callback (13 answers) Closed 5 months ago. I’m having some trouble with plain old JavaScript (no frameworks) in referencing my object in a callback function. function foo(id) { this.dom = document.getElementById(id); = 5; var self = this; this.dom.addEventListener(“click”, self.onclick, false); … Read more

method called after release() exception unable to resume with android camera

While developing a camera app I’ve encountered an exception that only happened when I switch to other app (onPause() for my app). 01-15 17:22:15.017: E/AndroidRuntime(14336): FATAL EXCEPTION: main 01-15 17:22:15.017: E/AndroidRuntime(14336): java.lang.RuntimeException: Method called after release() 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.hardware.Camera.setPreviewDisplay(Native Method) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.hardware.Camera.setPreviewDisplay( 01-15 17:22:15.017: E/AndroidRuntime(14336): at com.sora.cbir.yuki.image.leaf.CameraPreview.surfaceCreated( 01-15 17:22:15.017: E/AndroidRuntime(14336): … Read more

What are the benefits to using anonymous functions instead of named functions for callbacks and parameters in JavaScript event code?

I’m new-ish to JavaScript. I understand many of the concepts of the language, I’ve been reading up on the prototype inheritance model, and I’m whetting my whistle with more and more interactive front-end stuff. It’s an interesting language, but I’m always a bit turned off by the callback spaghetti that is typical of many non-trivial … Read more

Pass extra parameters to an event handler?

Let’s say I want to pass some extra data when assigning an event handler. Consider the following code: private void setup(string someData) { Object.assignHandler(evHandler); } public void evHandler(Object sender) { // need someData here!!! } How would I go about getting someData into my evHandler method? Answer private void setup(string someData) { Object.assignHandler((sender) => evHandler(sender,someData)); … Read more

Python subprocess: callback when cmd exits

I’m currently launching a programme using subprocess.Popen(cmd, shell=TRUE) I’m fairly new to Python, but it ‘feels’ like there ought to be some api that lets me do something similar to: subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit) I am doing this so that function_to_call_on_exit can do something based on knowing that the cmd has exited (for example keeping count … Read more