Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:23:48+00:00 2026-06-02T11:23:48+00:00

Below in Message I use the pattern and it works fine. There is only

  • 0

Below in Message I use the pattern and it works fine. There is only one instance of message[] and it is private. Display is public as that is how I use the object.

Regarding the second object – Effects

A default way,

I was going to update Effects to this pattern simply because I want to make it the default way I write Object Oriented JavaScript.

Are there other / better things to take into consideration or is this a good starting point for writing objects.

In C++ a default starting point might be:

class MyClass
{
private:
protected:
public:
};

Also, A potential inefficiency

Effects simply fades in or fades out an element. I make the timer a property of element to avoid flickering. Doing this only allows one opacity level to be set per element.

However, this leads me to believe that at times I have multiple effects instances running on the same element. They just happen to be doing the exact same thing because they share the same timer.

/**
 *Message
 *  element - holds the element to send the message to via .innerHTML
 *  type - determines the message to send
 */

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 passoword, 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:me@host.com">support</a> to reset your password',
    };
    var Message = function (element) 
    {
        this.element = element;
    };
    Message.prototype.display = function( type ) 
    {
        this.element.innerHTML = messages[ type ];
        new Effects().fade( this.element, 'down', 4000 );
    };
    return Message;
}());

Effects

/**
 *Effects - build out as needed
 *  element - holds the element to fade
 *  direction - determines which way to fade the element
 *  max_time - length of the fade
 */

var Effects = function(  ) 
{
    this.fade = function( element, direction, max_time ) 
    {
        element.elapsed = 0;
        clearTimeout( element.timeout_id );
        function next() 
        {
            element.elapsed += 10;
            if ( direction === 'up' )
            {
                element.style.opacity = element.elapsed / max_time;
            }
            else if ( direction === 'down' )
            {
                element.style.opacity = ( max_time - element.elapsed ) / max_time;
            }
            if ( element.elapsed <= max_time ) 
            {
                element.timeout_id = setTimeout( next, 10 );
            }
        }
    next();
    }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:23:50+00:00Added an answer on June 2, 2026 at 11:23 am

    Here is one way to implement a module with an internal constructor constructMessage(element) that is also exposed publicly, private variable $messages, and the private function internalDisplay(type, effects).

    Notice that effects is a parameter to the function display(type, effects). This eases unit-testing because you can then pass in mock Effects.

    The code is a common way to do namespaces and private members in JavaScript. As you can see, your “class” can have private functions that you selectively expose to the outside.

    Finally, the module and “class” names aren’t the best, but they are good enough for this simple example.

    var MessageModule = MessageModule || (function () {
    
        function constructMessage(element) {
    
            var messages = {
                name:         'Please enter a valid name', 
                email:        'Please enter a valid email', 
                email_s:      'Please enter a valid email.', 
                pass:         'Please enter passoword, 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 support to reset your password' 
            };
    
            function internalDisplay(type, effects) {
                element.innerHTML = messages[type];
                effects.fade(element, "down", 4000);
            }
    
            return {
                display: internalDisplay
            };
        }
    
        return {
            Message: constructMessage
        };
    })();
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e)
In the message object below, if I call it like this: var message_object =
Below is a Switch / Case statement that displays an error message when an
I'm getting this error message with the code below: class Money { public: Money(float
I get the below error message. What other compression function(other than SHA1) should use
when I use command spec path/to/spec_file.rb then it come with the message below. I
I use below code for accelerometer and it works on ipod 3g but doesn't
I'm parsing an email using the below style message = Mail.new(body) #where body is
I have a SOAP message (see below). Using Xpath, how can I extract the
I got the Error message in Android below, it is send by PHP server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.