2013-03-03 6 views
5

में जावास्क्रिप्ट कॉलबैक पर ऑब्जेक्ट को कैसे पास किया जाए, मैं एक नोड मॉड्यूल पर काम कर रहा हूं, और एक क्लास के उदाहरण को पास करने की कोशिश कर रहा हूं जो ObjectWrap को जावास्क्रिप्ट कॉलबैक के तर्क के रूप में उप-वर्ग बनाता है।वी 8

अन्य स्थानों में मैं कर लिया है सफलतापूर्वक खोलना जावास्क्रिप्ट एक ही कक्षा के लिए वस्तुओं का उपयोग करते हुए:

GitCommit *commit = ObjectWrap::Unwrap<GitCommit>(args[0]->ToObject()); 

मैं रिवर्स करना कैसे सकता है?

Local<Value> argv[] = { 
    // Error code 
    Local<Value>::New(Integer::New(0)), 
    // The commit 
    commit // Instance of GitCommit : ObjectWrap 
}; 

// Both error code and the commit are passed, JS equiv: callback(error, commit)  
ar->callback->Call(Context::GetCurrent()->Global(), 1, argv); 

यह संभव है: मैं की तरह, एक जावास्क्रिप्ट कॉलबैक करने GitCommit का एक उदाहरण पारित करने के लिए करना चाहते हैं? यदि ऐसा है तो कृपया मुझे एक उदाहरण दें, या प्रासंगिक दस्तावेज का लिंक दें?

उत्तर

3

तो आप एक नोड एडन लिख रहे हैं। आज़माएं:

Handle<Value> argv[] = { 
    // Error code 
    Integer::New(0), 
    // The commit 
    commit->handle_ // Instance of GitCommit : ObjectWrap 
}; 

// Both error code and the commit are passed, JS equiv: callback(error, commit)  
ar->callback->Call(Context::GetCurrent()->Global(), 1, argv); 
+0

धन्यवाद * इसके लिए बहुत * बहुत कुछ! –

संबंधित मुद्दे