Tuesday, 15 January 2013

node.js - Javascript Performance in Node modules -



node.js - Javascript Performance in Node modules -

i have code in module looks this:

var mymodule = module.exports; mymodule.some_function = function(arg) { // code here // logging using function name // var function_name = calleeargs.callee.tostring().match(/function ([^\(]+)/)[1]; // bad, method doesnt have name };

the code above not work function not have name. alternative, following, in case log contain method name:

function _some_function(arg) { // code here // logging using function name - bad, method doesnt have name // var function_name = calleeargs.callee.tostring().match(/function ([^\(]+)/)[1]; // goo, method doesnt have name } mymodule.some_function = function(arg) { _some_function(arg); };

so question is:

1.) way of writing create sense - far understand _some_function() local module there no negative implications far global scope/access concerned

2.) (the sec option) have performance implications? (my guess of course of study no, or @ to the lowest degree relatively negligible)?

1) find code style confusing , bloated. think next cleanest approach:

function some_function(arg) { // code here // logging using function name } // set exports @ end exports.some_function = some_function;

2) function wrapping function add together negligible overhead, should avoided if adds no value.

javascript node.js performance

No comments:

Post a Comment