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 8326653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:49:58+00:00 2026-06-09T00:49:58+00:00

I use dependency injection in PHP ( tagged b.c. used as a comparison )

  • 0

I use dependency injection in PHP ( tagged b.c. used as a comparison ) as this seems to be best practice. PHP has more constructs for OO programming but it seems as doable to use DI in JavaScript as well to have de-coupled code.

In my instance it is a bit complicated b.c. my object contains object properties( function objects) that each have their own dependencies.

Here is the code in question that has 3 dependencies that I created inside the top level object but am considering injecting.

Where exactly would I inject them as they are used in different function objects with in the single object MC.MATweet?

The 3 objects are SText, SMessage, and SUniversals.

/**
 **  MATweet - Text, Universal, Message - Inject?
 */

MC.MATweet = { 
    init: function() {
        var tweet_button = document.getElementById( 'po_but' ),
            tweet_input = document.getElementById( 'po_in' );
        tweet_button.addEventListener( "click", function() {
            MC.Controller( MC.o_p( 'MATweet' ) ); 
        }, false ); 
        tweet_input.addEventListener( "keypress", function( event ) {
            if( event.keyCode === 13 ) {
                MC.Controller( MC.o_p( 'MATweet' ) );  
                event.preventDefault();
            }
        }, false );
        sStyle( [ "po_in","po_lab" ] );
    },
    pre : function( o_p ) {
        var form_elements = document.getElementById( 'fo_po' ).elements,
            text_object = new SText( form_elements ),
            universal_object = new SUniversals();
        if( universal_object.get('load') === '1' )
        {
            if( !text_object.checkEmpty() ) {
                return MC.MATweet.message( 'empty', o_p );
            }
            if( !text_object.checkPattern( 'tweet' ) ) {
                return MC.MATweet.message( 'tweet', o_p );
            }
        }
        o_p.args.hash = localStorage.hash;
        o_p.page = text_object.getArray();
        return o_p;
    },
    post : function( o_p ) {
       if( o_p.server.result === 'true' ) {
            MC.C.resetView( 'po_in' ); 
            vTPane( o_p.server.tweets ); 
        }
    },
    message: function( type, o_p )
    {
        var response_element = document.getElementById( 'i_box_rr' ),
            pane_element = document.getElementById( 'i_box_r_post' ),
            message_object = new SMessage( response_element ),
            cover_element = document.getElementById( 'po_but_cov' );

        o_p.result = 'complete';
        message_object.display( type );
        cover_element.style.display = 'inline';
        MC.MATweet.movePane( pane_element, 30, 'down' );
        return o_p;
    },
    movePane: function( pane_element, pos, dir ) {
        if( ( dir === 'down' ) && ( pos < 70 ) ) {
            pos += 1;
            pane_element.style.top = ( pos ) + 'px';
            setTimeout( function( ){ MC.MATweet.movePane( pane_element, pos, dir ); }, 1 );
        }
        else if( ( dir === 'down' ) && pos === 70 ) { 
            dir = 'up';
            setTimeout( function( ){ MC.MATweet.movePane( pane_element, pos, dir ); }, 2000 );
        }
        else if( ( dir === 'up' ) && ( pos > 30 ) ) {
            pos -= 1;
            pane_element.style.top = ( pos ) + 'px';
            setTimeout( function( ){ MC.MATweet.movePane( pane_element, pos, dir ); }, 1 );
        }
        else if( ( dir === 'up' ) && ( pos === 30 ) ) {
            document.getElementById( 'po_but_cov' ).style.display='none';
        }
    },
};
  • 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-09T00:49:59+00:00Added an answer on June 9, 2026 at 12:49 am

    We have found dependency injection, in the classical sense, to be useful in JavaScript. Here are some previous answers of mine on that topic, with some nice sample code in each:

    • Node.js: Best way to pass common variables into separate modules
    • Dependency injection with RequireJS
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've always used Spring's dependency injection to get datasource objects and use them in
I would like to use this pattern to enable dependency injection in my code.
We're trying to use Dependency Injection for a WCF Service. The Service has a
I'm trying to figure out the best practices for dependency injection in PHP. Question:
All my PHP is Object Orinted and I want to use dependency injection for
I am learning to use dependency injection with ninject. Most of the properties and
Take the following article for example: http://weblogs.asp.net/psteele/archive/2009/11/23/use-dependency-injection-to-simplify-application-settings.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+dotnetmvp+%28Patrick+Steele%27s+.NET+Blog%29 I don't see what benefit there is
I thought of applying Dependency Injection and use Unity in the Project I am
I am interested in applying dependency injection to my current project, which makes use
I'm using Ninject 3.0.1.10 for dependency injection and want to use Ninject.Extensions.Logging 3.0.1.0 for

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.