I am passing a plex object consisting of goog.structs.Set
from my content script to background page through chrome.extension.SendMessage
API. On the other side, this goog.structs.Set
is received as an Object
.
How can I typecast it back to goog.structs.Set
so that I can call various methods on it?
I am passing a plex object consisting of goog.structs.Set
from my content script to background page through chrome.extension.SendMessage
API. On the other side, this goog.structs.Set
is received as an Object
.
How can I typecast it back to goog.structs.Set
so that I can call various methods on it?
- Before sending the plex object, I convert goog.structs.Set to an array. See @John answer's below for an alternative – vivek.m Commented Sep 9, 2013 at 9:13
3 Answers
Reset to default 10Do you mean for the closure piler?
function receiveStructsSet( aSetObject ){
var mySet = /** @type {goog.structs.Set} */ (aSetObject);
}
See http://developer.chrome./extensions/messaging.html, you can only pass JSON using chrome.extension.SendMessage.
Personally, I use a simple object as a set and avoid goog.structs.Set:
var MySet = Object.create(null);
If use must use goog.structs.Set, you will need to serialize and deserialize it to JSON.
You can also use the annotation before the function declaration
/**
* @param {goog.structs.Set} aSetObject description of object
*/
function receiveStructsSet( aSetObject ){
aSetObject.getCount();
}