Question

I am passing a complex 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?

Was it helpful?

Solution 2

See http://developer.chrome.com/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.

OTHER TIPS

Do you mean for the closure compiler?

function receiveStructsSet( aSetObject ){

    var mySet =  /** @type {goog.structs.Set} */ (aSetObject); 
}

You can also use the annotation before the function declaration

/**
 *  @param {goog.structs.Set} aSetObject description of object
 */
function receiveStructsSet( aSetObject ){
  aSetObject.getCount();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top