WebKit JS callback functions(3)

来源:互联网 发布:tensorflow图像预处理 编辑:程序博客网 时间:2024/05/22 09:48

In JSC, we can implement an JS function easily, however it may be hard for us to implement an JS function with one or more callback functions, like:

 

window.ourOwnFunction("param1", "param2", function(e){alert(e);});

 

Now I will explain how to implement this.

 

First, given that we have implemented this JS extention: window.ourOwnFunction("param1", "param2")

 

Second, define this function as: 

[Custom] ourOwnFunction(in DOMString, in DOMString, in [Callback, optional] OurCallbackFunc);

 

[Custom] is optional if you will implement the whole class of "OurCallbackFunc", else please use it to implement it on our own way.

 

Then, add four new files:

OurCallback.idl

OurCallback.h

JSOurCallbackCustom.h

JSOurCallbackCustom.cpp

 

Finally, modify the following files to implement the function invoking:

JSDOMWindowCustom.cpp

DOMWindow.cpp

 

Normally, we have done the process.

 

Now, let's test it.

 

<sctipt>

function callbackFunc(e)

{ alert(e); }

 

window.ourOwnFunction('a', 'b', callbackFunc);

</script>

原创粉丝点击