Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

The code below works, and I'm not that unhappy with it, it just feels a bit awkward. Is there a cleaner way to setup an electrolyte component with multiple methods on the object? The examples don't show how to setup with multiple class methods (unless I'm misreading).

exports = module.exports = function(say) {
    //private
    var count = 0;

    var retObj; = {
        mary: function() {
            count++;
            console.log(say.hello() + 'Mary' + count + "\n");
        }
    }

    return retObj;;
};


exports['@require'] = ['Say'];
share|improve this question

closed as off-topic by rolfl Jun 12 at 13:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – rolfl
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Please do not add, remove, or edit code in a question after you've received an answer. The site policy is explained in What to do when someone answers. –  Mast Jun 12 at 13:26
    
it was apparent that the question answered was not the question I was trying to ask. Cleaning up the code to better communicate intent was the wrong thing to do? –  skarface Jun 12 at 13:28
    
Have you read the link? –  Mast Jun 12 at 13:28
    
Yes. The answer, in this particular case was completely wrong (correct in general, but wrong in the context of my intended question), largely because I believe the code I posted didn't sufficiently describe the problem I was trying to solve. This particular case did not seem to be covered in the link. Better to adjust and get answers to my actual question, or not adjust and leave the answer about a typo, so future generations can see that ;; is bad form? :) –  skarface Jun 12 at 13:34
    
skarface - Site policy is that code cannot be edited after the question is answered. That is clear in the meta post linked above. The fact that your preparation when asking this question was insufficient is not a good enough reason to make an exception case for you. Please read the help center and the linked post above, again. –  rolfl Jun 12 at 13:39

1 Answer 1

Your style of using both exports and module.exports seems confusing. Make sure you're using the right tool for the right job. For more information about the difference, see HackSparrow on exports vs module exports or the answers on this SO answer.

Are you aware of the ; in var retObj; = {? I would expect a : there.

You're naming your function mary in mary: function() { while no name is required. You're not referring to the function by the name so an anonymous function would suffice.

There are two ; in return retObj;;, which is unnecessary and ugly.

var retObj; = {
    mary: function() {
        count++;
        console.log(say.hello() + 'Mary' + count + "\n");
    }
}

Could be written as:

var retObj = function() {
    count++;
    console.log(say.hello() + 'Mary' + count + "\n");
}

Which is easier to read and less clunky.

share|improve this answer
    
the double ;; was a typo :) The fact that I only had one property was just to shorten the example. I actually want to be able to resultant object to have multiple methods. My question more focused on how to create a valid constructor for electrolyte without having to set the methods in retObj. npmjs.com/package/electrolyte –  skarface Jun 12 at 11:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.