Tuesday 27 June 2017

Initializing Objects inside functions

What's your take on initializing Objects inside functions. E.g. aws-sdk needs to be initialized inside each function in order to be mocked.Like this:const AWS = require('aws-sdk'); module.exports.getRecord = function (id) { const client = new AWS.DynamoDB.DocumentClient(); return client.get({....}).promise(); } instead of:const AWS = require('aws-sdk'); const client = new AWS.DynamoDB.DocumentClient(); module.exports.getRecord = function (id) { return client.get({....}).promise(); } Will this have an impact on performance/memory? Are there any drawbacks?

Submitted June 27, 2017 at 09:21PM by kostarelo

No comments:

Post a Comment