WebKit JS callback functions(3)

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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章