I do not believe you lose the object ref, which seems (without knowing more about the call context ) to be root windows object when calling google.script.
Have you tried to use your function as :
var parent = .. ; // myContextObject which will be used as 'this'
var HandshakeFn = function(){..};
var Handshake = HandshakeFn.call(parent);
To clarify the answer, every function call in javascript is owned by an object (the context), which is default as window (the root). When you call the Handshake function as you have done using
Handshake = (function(){...})();
the context 'this' is the object from where it has been called. Because you call your function directly from the root, any reference to 'this' in the function will return a ref to the window.
To avoid this behavior, you may explicitly set the calling context using
HandshakeFn.call(myobject);
With that, 'this' will refer to myobject instead of window. And when you set the user object to googlescript it will return the proper object in the second 'parent" parameters.
What i suggest here is to avoid dealing with the context and second parameter with google script
var Handshake = (function () {
var self = {}; // you need to explicitely create an object here !
google.script.run.withSuccessHandler(parse).withFailureHandler(onFailure).getContacts();
console.log("JUST CALLED GET CONTACTS");
function parse (JSONstring)
{
self.contacts = JSON.parse(JSONstring);
console.log ("Parsed info "+JSON.stringify(self));
}
return self;
}());
Do not forget to vote if you find this useful.
P.S. : Sorry for my poor English, it is not my native language.
regards.