2012-09-10 29 views
0

在此先感謝。如何在異步函數中使用javascript對象

我正在創建一個函數,如下所示。 // requestFile在NPAPI插件中實現,當任務完成時將initFS作爲NPObject獲取,我在此對象上調用NPN_InvokeDefault。

window.requestFile("test",true,initFS); 
//After this function initFS is getting called. 
function initFS(fs) { 
alert('Inside initFS'); //alert is coming. 
//testFunc is implemented in NPAPI Plugin, it will return true if it is get called 
alert(fs.testFunc()); // It is not getting called. 
alert(fs.testCall()); //It is not getting called. 
} 
function testCall() { 
alert('Inside testCall function'); 
} 

我沒有得到它在調用NPN_InvokeDefault後從Plugin返回哪種對象。以及如何在JavaScript中使用它。具體而言,我想專門爲我的插件返回NPObject,並想從JavaScript調用插件方法。

如何在NPAPI插件中使用Asynchronous Javascipt函數?任何樣品將不勝感激。

回答

1

使用此(fiddle)爲起點:

var testcall=function() { 
    alert('Inside testCall function'); 
    } 

    var fs={ 
     testFunc: function(){console.log("succes")}, 
     testCall:testcall 
    } 


    //After this function initFS is getting called. 

    initFS(fs) //<--PASS in fs also 

function initFS(fs) { 
    alert('Inside initFS'); 
    //testFunc is implemented in NPAPI Plugin, it will return true if it is get called 
    fs.testFunc(); // It is not getting called. 
    fs.testCall(); //It is not getting called. 
    } 

您需要在fs對象傳遞到initFS

+0

感謝小方與它的工作原理!!!! –

相關問題