Message from JavaScript discussions

June 2017

— Heh, I always try to keep my functions tiny


Like this:

function newThing () {
var thing = new Thing();
return thing.public;

— I see

— I don't think I've ever had the need to share privates with 'friends' that can't just be public

— And the function definition for the thunk must be scope restricted so that it may see the event bus or friend classes, while the user cannot

Message permanent page

— Heh, in a large framework or library it can get a little crazy

— SendFriends would be an emitter-type pattern?

— Yes. In my real use case it is attaching objects in a component pattern in such a way that the attachee can access members you would not want to expose

Message permanent page

— I see

— So


— You could do that with weakmaps too, heh

— Friends.set(thing, private)