You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constSomething=function(element){// |this| is a newly created objectthis.name='Something Good';this.handleEvent=function(event){console.log(this.name);// 'Something Good', as this is bound to newly created objectswitch(event.type){case'click':
// some code here...break;case'dblclick':
// some code here...break;}};// Note that the listeners in this case are |this|, not this.handleEventelement.addEventListener('click',this,false);element.addEventListener('dblclick',this,false);// You can properly remove the listenerselement.removeEventListener('click',this,false);element.removeEventListener('dblclick',this,false);}consts=newSomething(window);// changed document.body to window for the demo
Defining a window object in C# as follows, I received the call to the addEventListener method.
However, for the above script, the listenerValue.Value is JSObject (not Function as in all other cases). How do I invoke/call the JS handler in this case?
The text was updated successfully, but these errors were encountered:
I did not immediately understand the details of the question. As I can see, you want to invoke method handleEvent for Something. For this you should to get value of property handleEvent from object via GetProperty("handleEvent"), then cast this value to a Function and call it via Function.Call(...) with passing listener as this
@nilproject Thanks for the reply. This is about integrating a scripting into an SVG rendering library. So that will be a user written script and the handleEvent method is not known to the rendering library.
When you run this script in ClearScript.V8 engine, the listener is a ScriptObject as with other listeners and calling the invoke method defined on this object instance will automatically invoke the handleEvent method, since in this case as stated in the comment,
// Note that the listeners in this case are |this|, not this.handleEvent
This sample is found on the Mozilla site: addEventListener
Defining a
window
object in C# as follows, I received the call to theaddEventListener
method.However, for the above script, the
listenerValue.Value
isJSObject
(notFunction
as in all other cases). How do I invoke/call the JS handler in this case?The text was updated successfully, but these errors were encountered: