I am trying to share a specific javascript "object definition" (class) between server and client. On the server I use Node
with Express
and on the client Angular
. (so far no database, therefore not the entire MEAN stack) The objects will be send via JSON
and socket.io
.
Example:
'use strict';
var Foo = function (fid) {
this.fid = fid;
this.toJSON = function () {
return ('{"fid":"' + this.fid + '"}');
};
};
Foo.fromJSON = function (json) {
var obj = JSON.parse(json);
return new Map(obj.fid);
};
For now the Foo
code is inside a separate file. I guess I need to change my "object definition"? If yes, how? Where do I put it in my project structure? (I use this structure.)
thanks