如何在异步函数中使用javascript对象

时间:2012-09-10 15:28:46

标签: javascript npapi

提前致谢。

我正在创建一个函数,如下所示。 // 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后从插件返回哪种对象。以及如何在javascript中使用它。具体来说,我想专门为我的插件返回NPObject,并希望从javascript调用插件方法。

如何使用NPAPI插件的异步Javascipt函数?任何样品都将受到赞赏。

1 个答案:

答案 0 :(得分: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

相关问题