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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:17:50+00:00 2026-06-02T15:17:50+00:00

I am trying to properly annotate all my Javascript code and am still a

  • 0

I am trying to properly annotate all my Javascript code and am still a beginner in this field.

I get objects from a server call that are directly in json. Those objects are passed to functions and I call members directly. It obviously is very error prone while obfuscating so I am trying to annotate everything properly.

My understanding is that (i) I should create a class for this object even though it is never created directly with new and (ii) I should be careful with member names since they are fixed by the server response and should not be changed (or should be aliased beforehand).

I have two questions: are my asumptions correct ? how to do the annotation based on that.

Here is a sample code to illustrate

$.get("url.php", function(data) {
    process(data);}, "json"); // <= returns {"a":"abc","b":1}

function process(data) {
  $("#someElement").html(data.a + data.b);
}

Here is the class I was planning on creating for closure compilation purposes

/**
 * The object that is sent back from the server
 * @constructor
 */
function ServerResponse() {
  /** @type {string} a */
  this["a"] = "";
  /** @type {number} b */
  this["b"] = 0;
}

Here is the annotation for my process function

/**
 * Process data from the server
 * @param {ServerResponse} data: the Object sent back from the server
 */

Is my annotation correct? Is it robust to obfuscation?

Thanks a lot for your help

  • 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-02T15:17:52+00:00Added an answer on June 2, 2026 at 3:17 pm

    If you quote property names, you need to quote them consistently at every usage. If you haven’t see this, you should read:

    https://developers.google.com/closure/compiler/docs/api-tutorial3

    So that your first snippet would be:

    function process(data) {
      $("#someElement").html(data['a'] + data['b']);
    }
    

    If you are trying to avoid quoting or if you would like the compiler to type check the usage of the properties (quoted properties references are not checked), you should define an extern file to include with the compilation of your source:

    /** 
     * @fileoverview
     * @externs
     */
    
    /** @interface */
    function ServerResponse() {}
    /** @type {string} */
    ServerResponse.prototype.a;
    /** @type {number} */
    ServerResponse.prototype.b;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling with trying to get this piece of code working properly. I'm moving
So I'm trying to properly implement licensing into my live wallpaper. All the code
I'm stuck trying to get this helper to work properly. This is what I
I am trying to annotate my Javascript properly in order to avoid Google Closure
I'm messing with core.time.Duration s - in particular, I'm trying to properly get number
I am trying to get my JSON encoded array formatted properly. Here is my
I've been trying to get colourschemes to work properly in VIM when using it
I'm unable to get SQL and Rails to play properly when trying to find
I am trying to figure out how to properly parse some values returned from
I'm currently trying to create a C source code which properly handles I/O whatever

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.