Sunday, October 2, 2016

newing from dynamically-loaded type

newing an object from a dynamically-loaded/reflected type from statically language such as C# and Java requires an API (e.g., Activator.CreateInstance for C# developers). Whereas in node you can still use the new keyword

> new (require('./api/-core/protocol-buffer/proto-mapping')['com.puter.platform.protocols.users.AccountUpdated'])({account: { uuid: {id: '021e4feb-99c4-419b-8891-b38bd6b00897'}}}).encode64();

Don't forget the parenthesis after the new keyword.

Have yet to know what's the difference of the above dynamic object creation from ES6's Reflect.construct.

Happy Coding!

No comments:

Post a Comment