Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Is this best practice way to send messages to the user?

Update: This has been changed to a simple function call.

/**
 *Message - Sends message to the .innerHTML of an element
 */

var Message = ( function () 
{
    var messages = 
    {
        name:         'Please enter a valid name',
        email:        'Please enter a valid email',
        email_s:      'Please enter a valid email.',
        pass:         'Please enter password, 6-40 characters',
        url:          'Please enter a valid url',
        title:        'Please enter a valid title',
        tweet:        'Please enter a valid tweet',
        empty:        'Please complete all fields',
        same:         'Please make emails equal',
        taken:        'Sorry, that email is taken',
        validate:     'Please contact <a class="d" href="mailto:[email protected]">support</a> to reset your password',
    };
    var MessageInternal = function (element) 
    {
        this.element = element;
    };
    MessageInternal.prototype.display = function( type ) 
    {
        this.element.innerHTML = messages[ type ];
    };
    return MessageInternal;
} () );
share|improve this question

1 Answer

up vote 2 down vote accepted

I don't really understand what you are asking here, but I'll give some general pointers:

  • I find that you have two different variables called Message very confusing.

  • It's not really a good idea to add proprietary properties to DOM elements. You should consider using the HTML5 dataset API instead.

  • It seems wrong to hard code the fade effect.

  • IMHO this seems like a lot of code and unnecessarily over-engineered for displaying a simple message. It reminds me a lot how of the Twitter bootstrap library does things.

share|improve this answer
- decided to go with a simple function instead of module pattern. – Hiro Protagonist Jun 17 '12 at 21:44
- how is HTML 5 related here?...are you referring to the HTML5 data- attribute? – Hiro Protagonist Jun 17 '12 at 21:45
this is what you mean by dataset API methinks – Hiro Protagonist Jun 18 '12 at 15:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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