2011-04-19 55 views
0

檢索參數值,說我有在JS function playerJob(job){}JQuery的/ JS:從功能

我使用Awesomium,調用由C這種方法++函數基本上說

int currentJob = GameModeState::changeJob(false); 
mScreen->executeJavascript("map.playerJob(currentJob);"); 

所有我想讓你看到的是我給我的JS功能playerJob它的參數值。


我想要做的就是然後用我的JS內playerJob找出值job是什麼。我想爲該值設置一個變量。我不知道如何從我的方法中獲取該值,而無需輸入參數。說我有我的方法是

function playerJob(job) { 
    return job; 
} 

我試着說讓工作:

var currentJob = playerJob();

這不起作用,可能是因爲我需要把一些括號內。

我知道我可以使用playerJob這樣的:

function playerJob(job) { 
    someOtherFunction(job); 
} 

但問題是,我需要這個job變量之前我調用任何常規的「功能」。我需要在一個內部使用它

$(document).ready(function() 
{ 
    $("#div").click(function(e) 
    { 

我不能「打電話」。

有沒有使用JQuery從我的playerJob函數中獲取該變量的方法?

回答

1

也許保持一個全局變量是在這種情況下正確的解決方案。

var currentJob=null; 
//var currentJob="Default Job; 

function playerJob(job) { 
    if (job) currentJob=job; // <------- UPDATED 
    someOtherFunction(job); 
} 

$("#div").click(function(e){ 
    if (currentJob) alert(currentJob); 
} 
+0

我正在玩這個。我認爲它正在工作,但我會先確認。 – Briz 2011-04-19 15:02:12

+0

currentJob似乎仍然是「空」,但這可能是我設置playerJob的問題。仍在使用〜 – Briz 2011-04-19 15:11:42

+0

如果您正在調用沒有參數的函數,currentJob將保持爲空。查看更新 – Dutchie432 2011-04-19 15:26:57