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

  • Home
  • SEARCH
  • 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 8665161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:25:01+00:00 2026-06-12T17:25:01+00:00

When javascript is run in the browser there is no need to try and

  • 0

When javascript is run in the browser there is no need to try and hide function code because it is downloaded and viewable in source.

When run on the server the situation changes. There are use cases such as api where you want to provide users with functions to call without allowing them to view the code that which is run.

On our specific case we want to execute user submitted javascript inside node. We are able to sandbox node.js api however we would like to add our own api to this sandbox without users being able to toString the function to view the code which is run.

Does anyone have a pattern or know of a way of preventing users from outputting a functions code?

Update:

Here is a full solution (i believe) based on the accepted answer below. Please note that although this is demonstrated using client side code. You would not use this client side as someone can see the contents of your hidden function by simply reading the downloaded code (although it may provide some basic slow down to inspect the code if you have used a minify).

This is meant for server side use where you want to allow users to run api code within a sandbox env but not allow them to view what the api’s do. The sandbox in this code is only to demonstrate the point. It is not an actual sandbox implementation.

// function which hides another function by returning an anonymous
// function which calls  the hidden function (ie. places the hidden
// function in a closure to enable access when the wraped function is passed to the sandbox) 
function wrapFunc(funcToHide) {
  var shownFunc = function() {
    funcToHide();
  };
  return shownFunc;
}

// function whose contents you want to hide
function secretFunc() {
  alert('hello');            
}

// api object (will be passed to the sandbox to enable access to
// the hidden function)
var apiFunc = wrapFunc(secretFunc);
var api = {};
api.apiFunc = apiFunc;

// sandbox (not an actual sandbox implementation - just for demo)
(function(api) {
  console.log(api);
  alert(api.apiFunc.toString());
  api.apiFunc();
})(api);
  • 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-12T17:25:02+00:00Added an answer on June 12, 2026 at 5:25 pm

    If you wrap a callback in a function, you can use another function in that scope which is actually hidden from the callback scope, thus:

    function hideCall(funcToHide) {
        var hiddenFunc = funcToHide;
        var shownFunc = function() {
            hiddenFunc();
        };
        return shownFunc;
    }
    

    Then run thusly

    var shtumCallBack = hideCall(secretSquirrelFunc);
    userCode.tryUnwindingThis(shtumCallBack);
    

    The userCode scope will not be able to access secretSquirrelFunc except to call it, because the scope it would need is that of the hideCall function which is not available.

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

Sidebar

Related Questions

I'd like some Javascript code to run when the mouse leaves the browser window.
Is there any way of getting the source code of an HTML browser-page that
Is there anyway to have javascript run when a XSL sheet has been applied
Want to run javascript function from parent window in child window Example I have
When I run javascript script file in windows command line environment, and there is
I'm using python-spidermonkey to run JavaScript code. In order to pass objects (instead of
I need to run a super long JavaScript on my page. The client is
When I run this code the page repeats its self. I also need it
Sorry to follow this topic http://stackoverflow.com/questions/11044825/javascript-run-on-ie-7 I want to use document.GetElementByClassName ON INTERNET EXPLORE
How to run javascript/Jquery functions on user specific time scenario its so simple 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.