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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:16+00:00 2026-05-28T14:00:16+00:00

Ok, I know what I am doing and I purposely want many multiple scripts

  • 0

Ok, I know what I am doing and I purposely want many multiple scripts like this to be on my page, because these scripts are not supposed to be evaluated on load, however if I set type=”something else” then I do not get intellisense and validation which creates trouble while development.

<script type="text/javascript" id="s">
{
    //                <- following '(' is unexpected
    update: function (o){
        alert(o);
    }
}
</script>

However when I do this, its alright,

<script type="text/javascript" id="s">
{
    update: function x(o){
        alert(o);
    }
}
</script>

Notice the “x” before round brackets. Problem is, if I write “x” then window.x is set to this method and writing multiple scripts creates even further problem.

When I change it to,

<script type="text/javascript" id="s">
{
    update: function x(o){
        alert("s-update: " + o);
    },
    method: function x(y){
        alert("s-method: " + y);
    }
}
</script>

Then I get unexpected token ‘,’ before method.

  1. I want to know how can I create just an JavaScript Object Notation which will be executed later on by giving ids. See working code at http://jsfiddle.net/MDJbT/, but I do get a script error if I include , and if I remove , then I get no script error but my code does not get executed, http://jsfiddle.net/2ykdD/1/.
  2. I need this in a framework which will allow us to write scripts in completely “id” independent way, so that there will not be any conflict of global methods. Both scripts have same names, but different logic. The only difference is the “id”, I know which ID to refer and which method to call.
  3. This is very small part of complicated framework where ids are automatically assigned and methods are part of class hierarchy which is dynamically set in runtime, preserving scope.
  4. I do not want these scripts to be executed at all.
  5. I want these scripts to be written in such way so that Visual Studio and other editors will precisely show intellisense and give errors about syntax etc.
  6. I will execute these scripts only on action invoked by user within an eval scope by providing further method arguements.
  • 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-28T14:00:17+00:00Added an answer on May 28, 2026 at 2:00 pm

    { indicates the start of a block in JavaScript, as is evident by the following piece of code (which is valid syntax):

    { var hello = "test" } 
    

    Internally, this is translated to the following sequence (remembering that variable declarations are hoisted and not block scoped):

    1. Define variable hello
    2. begin block delimited with {
    3. assign value “test” to Hello
    4. end block

    Ignoring the block, it’s equivalent to var hello = "test". If we apply this same logic to your code, then

    {
        //                <- following '(' is unexpected
        update: function (o){
            alert(o);
        }
    }
    

    is translated to the following sequence:

    1. begin block delimited by {
    2. define label update
    3. begin function statement
    4. throw syntax error

    Ignoring the block delimiters, the code is interpreted as:

    update: function (o){
        alert(o);
    }
    

    The reason for the syntax error is that a function statement must have a name. In your second example, the function statement is valid because it has a name. Both function statements have names in the 3rd but the , is invalid when following a function statement.

    As others have mentioned, the problem is fixed when you wrap the whole thing in braces, because the code becomes an expression and, therefore, legal syntax.

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

Sidebar

Related Questions

I know this probably really simple but Im not sure what im doing wrong...
I know I'm doing this a bad way... but I'm having trouble seeing any
Does anyone know the equivalent for doing this in Visual Studio 2008( EnvDTE90 )
I have an application consisting of many scripts doing some stuff on their own.
I want to know if this could be done. I am building a data
I am not sure if this question is not silly, but I really want
I know the regex for doing a global replace, %s/old/new/g How do you go
I know you can clear options by doing the following: dropDownList.options.length = 0; Is
Do you know any library that will help doing that? I would write a
I don't know what I'm doing wrong, but sorl-thumb just uploads the image but

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.