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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:31:55+00:00 2026-06-13T13:31:55+00:00

Is there a way to declare a static of final value in javascript so

  • 0

Is there a way to declare a static of final value in javascript so that it cannot be altered by a 3rd party?

What I have is a article sharing application, with free users being ad supported.
What I wish to do is prevent the free users from altering the innerHTML content by altering the storage variable for the content.

What I have at this moment is a timer that reloads the innerHTML of the article on user website every 5 seconds and I’m storing the value for the reload in a variable.

However, if a genius using jsbeatify explores which variable holds the key to removing the ad and alters that, we lose revenue and exposure of our products.

How to prevent the altering of the internal variable?


UPDATE

This is the end result of what I came up with:

http://jsfiddle.net/PgdYP/1/

<div id="specialdiv"></div>
<input type="button" value="try to change the function i to do something different" onclick="t.i = function(){alert(data.secret);}"><BR>
<input type="button" value="set function to null out of spite" onclick="t=null;">


 <script type="text/javascript">
    e = function(){var data = { };
    Object.defineProperty(data, 'secret', {
       value: "Hello world!",
       writable : false,
       enumerable : true,
       configurable : false
       });this.z=function(){window.setTimeout("try{document.getElementById('specialdiv').innerHTML =   '"+data.secret+"';t.i.z();}catch(err) {document.body.innerHTML=err;}",5000);}}
        g = function(){};
        g.prototype = new e();e=null;window.t = {}
        Object.defineProperty(window.t, 'i', {
        value: new g(),
        writable : false,
        enumerable : false,
        configurable : false });g = null;
        window.t = Object.freeze(window.t); t = Object.seal(window.t);
        t.i.z();
    </script>

This will be presented in packed format, just to make it harder just to copy the code out of the source.
This way the effort to simply copy and paste the code out will be maximized and will be very hard to automate.

Thank you all for your answers.

  • 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-13T13:31:56+00:00Added an answer on June 13, 2026 at 1:31 pm

    Yes, there is. At least for object properties, ES5 gave us the possiblity to alter the property descriptor flags by hand. So we can do that like

    var data = { };
    
    Object.defineProperty(data, 'secret', {
        value: 42,
        writable : false,
        enumerable : true,
        configurable : false
    });
    

    That way, we created a property secret with the value 42 within data, which cannot get modfied nor deleted.

    The caveat here is, that the genius (like you called it) will also be able to spot this code and just modify that, to again be able to change the content if he wishes to. You just can’t create a secured front-end javascript in that way. The code will always be available as plain-text for everybody.


    To make this more complete, you can also create an object and freeze it at some point, using Object.freeze() and/or Object.seal() to shutdown the option for enumerating, deleting and modifying on properties of an object.

    But again the word of caution: This is intended to affect your own code or foreign code, to prevent modifications by accident or on purpose at run time. There is no way to stop a developer since he can simply halt the execution of your script, before this even can take affect.

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

Sidebar

Related Questions

Is there a way to declare that the variable type of a generic class
Is there a way to declare static methods in cheetah? IE snippets.tmpl #def address($address,
Is there a way to do the following at the same time? static final
Is there any way to declare/define global/static objects of managed types ?
Is there any way to simply declare static NSString as defined int identifier ?
Is there any way can declare a bean in just like JSP UseBean in
Is there a way to declare which signals are subscribed by a Python application
Is there a way to declare a variable with a particular user-defined type in
Is there a way to declare an unsigned int in Java? Or the question
In AS3, is there a way to declare a variable in my base class

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.