Reputation: 3430
I have the following class.
class User
{
constructor( username )
{
this._username = username;
}
get username()
{
return this._username;
}
}
When I instantiate a User object and send it over the wire, it says that myUserObject.username
is undefined when I try to access it on the receiver end, but myUserObject._username
does contain the value I set in the sender. I am using zerorpc which is built on zeromq and messagepack. Is there something I can add or do differently to make this work? This problem also occurs for normal class functions.
Right now, my makeshift solution is to recreate the object on the receiver end by passing in the defective object into the constructor and reassigning the fields.
Sender:
import User from './User.js'
const client = new zerorpc.Client();
//code for client to connect
function createUser()
{
let user = new User( "kacy" );
console.log( user.username ); //kacy
client.invoke( 'createUser', user, someCallback );
}
Receiver:
import User from './User.js'
createUser( user )
{
console.log( user._username ); //kacy
console.log( user.username ); //undefined
let user2 = new User( user._username );
console.log( user2.username ); //kacy
}
Upvotes: 0
Views: 196
Reputation: 633
zerorpc doesn't send code trough the wire. username()
is a function and wont be sent over the network, while _username
is an attribute. zerorpc can send any json-like datatype, no more, no less.
Few reasons that I can think of behind this limitation:
eval()
it on the other sideUpvotes: 1