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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:17:56+00:00 2026-05-23T03:17:56+00:00

am I right to say that an instance of a function object is immutable

  • 0

am I right to say that an instance of a function object is immutable since there’s no way we could modify a function once its created?

Anyway, to rephrase my question:

  var f1=function(){
        return true;
    }

    //Now i pass **f1** into the function **G**, storing it to **g1**
    function G(f){
    return function(){
            return f();
    }
    }
    var g1=G(f1);

    //I will try to hack/do anything i can to **f1**
    //Now i will pass f1 to hacked piece of injection code which (assumingly) will try to hack f1


    g1(); // but I can be 100% sure this will still return me true

So now can I be sure that no matter what I do to f1, g1() will Forever return me true ?

Despite being interested in browsers with at least 0.5% of the internet users market share: I welcome answers that goes along the lines of “in [x] browser this is not safe because..”

I am aware that since the code is run at the client, if the client has a malicious intent he will be able to do whatever he want.. But this question is specifically targeted at protecting “users who do not have malicious intents”, in other words.. a normal user (if the user is a hacker than i don’t mind letting him mess with the functions anyway he wants since he’d get all the exceptions thrown in his face and that’s none of my business)

  • 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-23T03:17:57+00:00Added an answer on May 23, 2026 at 3:17 am

    You cannot stop the variable g1 from being reassigned on all browsers. Some browsers would allow you to define g1 as a constant thus:

    const g1 = G(f1);
    

    which would prevent the name g1 from being rebound, and you can use Object.defineProperty to define a read-only global property of window on others, but in general, there are no const definitions in JavaScript.

    To make it clearer, consider two scenarios:

    (1) An attacker can run code in the scope in which f1 is declared, and then other code reads f1.

    var f1 = ...;   // You define f1
    f1 = function () { return false; };  // Attacker code runs
    doSomethingWith(f1());  // Naive code reads f1 and calls it.
    

    The attacker succeeds in this case in confusing the naive code because they changed the value at f1.

    (2) An attacker runs code in the scope after f1 has been read.

    var f1 = ...;  // You define f1
    // Cautious code reads and stores f1 in a safe place for later use.
    (function () {
      var f = f1;
      setTimeout(0, function () { doSomethingWith(f()); });
    })();
    f1 = function () { return false; };  // Attacker code runs.
    

    The attacker fails in this case because the cautious code read the value of f1 before the attacker changed the value stored at f1, so the private f continues to return true.

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

Sidebar

Related Questions

For instance, the app could say something like, Please wait. or I'll be right
a:3:{i:0;i:4;i:1;i:3;i:2;i:2;} Am I right to say that this is an array of size 3
I want to have a function defined in a superclass that returns an instance
In a jsp file, is there a way to find a component on that
First of all I should probably say that the term 'constant object' is probably
Let's say I have a simple class called WebsterDictionary that has a function that
I have created a function that takes a SQL command and produces output that
Say I have an instance method that does many different things that I need
Is it right to use a private constant in the following situation: Say I
Here's the deal. My WinApp is running, right? in let's say process 'A'.It creates

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.