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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:34:11+00:00 2026-05-16T18:34:11+00:00

What kind of problems and pitfalls can one encounter while doing javascript includes (

  • 0

What kind of problems and pitfalls can one encounter while doing javascript includes (<script src="sample.js" type="text/javascript><script>) and how to avoid them?

I’m asking this because I just ran into an issue where I wrote my javascript code inside a velocity template file which is included in an overall layout template. The layout template has many different javascript included. My javascript code works just fine on a page by itself, but when included with the layout template, it started to break. (No javascript errors, but things weren’t working).

  • 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-05-16T18:34:12+00:00Added an answer on May 16, 2026 at 6:34 pm

    sounds like you’re having a collision of global objects. your best bet in this scenario is to move all your code into a namespace, by which I mean create an object or anonymous function to house the javascript code you’ve written.

    for example instead of just doing

    var myWord = 'hello!';
    alert(myWord);
    

    where the name myWord might already be in use, you could do

    (function() {
        var myWord = 'hello!';
        alert(myWord);
    })();
    

    or if you need things to persist,

    var myUniqueNamespace = new (function() {
        this.myWord = 'hello!';
    })();
    alert(myUniqueNamespace.myWord);
    

    where you only need to ensure that myUniqueNamespace is indeed a unique name, and you can add whatever names you like as properties to it.

    re closure comment: not quite, but we can make it one like this

    var myUniqueNamespace = new (function() {
        var myWord = 'hello!';
        this.sayWord = function() { return myWord; };
    })();
    alert(myUniqueNamespace.sayWord());
    

    myWord exists within the scope of the anonymous function used to create myUniqueNamespace, so you can’t get do it directly from the outside (similar to a private member in other languages). however the method sayWord is defined in the same scope as myWord and closes over it, meaning that access to myWord is maintained within the method defintion. that might not be the clearest explanation but I hope the example makes it clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain Breadth-first search to solve the below kind of problems I need
What kind of problems other than writing compilers can be solved using Lexers and
I'm having some kind of problems with one thing, i'm making an app and
What kind of problems might this cause? Is it better to install in a
I am a newbie for solving these kind of problems. I need to extract
Even though I've been reading other topics about my kind of problem, I can't
What kind of problems is better solved in Prolog than in Haskell? What are
Has anyone attempted this? Is it possible, and if so, what kind of problems
What are some great Learning resources? What kind of problems do I solve with
I have only installed Ruby1.9 on my machine. Have some kind of problems with

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.