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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:01:15+00:00 2026-06-15T13:01:15+00:00

Often I have this situation: var obj = { field: 2 }; and in

  • 0

Often I have this situation:

var obj = { field: 2 };

and in the code:

do_something( obj.fiel ); // note: field spelt wrong

ie The property is incorrectly typed. I want to detect these bugs as early as possible.

I wanted to seal the object, ie
obj = Object.seal(obj);

But that only seems to prevent errors like obj.fiel = 2; and does not throw errors when the field is simply read.

Is there any way to lock the object down so any read access to missing properties is detected and thrown?

thanks,
Paul

EDIT: Further info about the situation

  1. Plain javascript, no compilers.
  2. Libraries used by inexperienced programmers for math calc purposes. I want to limit their errors. I can spot a misspelt variable but they can’t.
  3. Want to detect as many errors as possible, as early as possible. ie at compile time (best), at runtime with thrown error as soon as wrong spelling encountered (ok), or when analysing results and finding incorrect calculation outputs (very very bad).
  4. Unit tests are not really an option as the purpose of the math is to discover new knowledge, thus the answers to the math is often not known in advance. And again, inexperienced programmers so hard to teach them unit testing.
  • 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-15T13:01:17+00:00Added an answer on June 15, 2026 at 1:01 pm

    I don’t think this will work in Javascript since objects are written like JSON and thus properties will be undefined or null but not throw an error.

    The solution will be writing a native getter/setter.

    var obj = {
        vars: {},
    
        set: function(index, value) {
            obj.vars[index] = value;
        },
    
        get: function(index) {
            if (typeof(vars[index]) == "undefined") {
                throw "Undefined property " + index;
            }
    
            return vars[index];
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have a situation in my Java code when I need to set
I often have this kind of situation - there's a simple plain class, say,
In my code I have often situations like this: public void MyMethod(string data) {
I often have the following situation in my PowerShell code: I have a function
I have to use several shaders. In this situation, which way is often prefered?
When creating gems, I often have a directory structure like this: |--lib |-- helpers.rb
Often when writing PHP I'll have it output some HTML like this - echo
I quite often have rows of code like the following: UPDATE my_table SET name
This situation happens a little often, your whole repository has 2MB and then someone
I have this situation that is really irritating me now. At random times with

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.