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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:59:21+00:00 2026-06-04T01:59:21+00:00

I have in a json object which stores a JavaScript say var jsonObj =

  • 0

I have in a json object which stores a JavaScript say

    var jsonObj = {
      "js": "var x=1;\n   callback(x);"
    }

Now to execute this JavaScript, I need to provide an implementation for callback. Lets say our callback just prints the value x.

How then am I supposed to make the call using jsonObj.js such that the given javascript executes and prints the value of x (callback prints the value).

I tried the eval function but either my syntax was wrong or perhaps eval is not used here at all.

Any help is appreciated. Thanks!!

Note: If it helps, I am actually writing a firefox plugin using gwt. This peace of code is written as a native JavaScript function.

  • 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-04T01:59:22+00:00Added an answer on June 4, 2026 at 1:59 am

    Assuming you want to pass in the callback, you’d use the Function constructor instead of eval, and define the parameters.

    var jsonObj = {
      "js": "var x=1;\n   callback(x);"
    };
    
    var f = Function('callback', jsonObj.js);
    

    Then you can pass the function argument:

    f(function(n) { alert(n); }); // 1
    

    http://jsfiddle.net/HWCVD/


    The Function constructor is designed such that the last argument you pass it is the body of the function, and all the preceding arguments are the parameters to the function.

    So if you want to add additional parameters, you’d just give them to the Function constructor.

    var jsonObj = {
      "js": "var x=y + 1;\n   callback(x);"
    };
    
    var f = Function('y', 'callback', jsonObj.js);
    

    Then pass the arguments:

    //  v-"y"
    //  v
      f(2, function(n) { alert(n); }); // 3
    //         ^
    //         ^-"callback" 
    

    http://jsfiddle.net/HWCVD/16

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

Sidebar

Related Questions

I have this json object (which i don't really know what is inside) and
I have a json object in my JavaScript file containing qs: {} which when
I have a JSON object which is generated by PHP. It's an object with
I have a form field which requires a json object as its value when
I have several TextField columns on my UserProfile object which contain JSON objects. I've
I have this json object : { msg_id:134, message:Dick, comment:[ { com_id:9, comment:test, msg_id:134,
For example lets say I have a JSON object that contains states and cities.
I have MySQL database, where I store the following BLOB (which contains JSON object)
I have a object that im serializing to a JSON object using JSON.Net. This
I have a simple json string which contains a collection of objects http://sandapps.com/InAppAds/ads.json.txt When

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.