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

Ask A Question

Stats

  • Questions 544k
  • Answers 544k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're trying to add a try block at the top… May 17, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer The source of your confusion appears to be that there… May 17, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer Try android:exported="false" in your manifest. May 17, 2026 at 6:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Can someone explain Breadth-first search to solve the below kind of problems I need
I have only installed Ruby1.9 on my machine. Have some kind of problems with
Has anyone attempted this? Is it possible, and if so, what kind of problems
What kind of programming problems are state machines most suited for? I have read
What kind of problems might this cause? Is it better to install in a
What kind of problems is better solved in Prolog than in Haskell? What are
What are some great Learning resources? What kind of problems do I solve with
What kind of problems on graphs is faster (in terms of big-O) to solve
I am confronted with a new kind of problem which I haven't encountered yet
Kind of a special case problem: I start a process with System.Diagnostics.Process.Start(..) The process

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.