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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:42:33+00:00 2026-06-17T07:42:33+00:00

Please find below a snippet of my Node.JS server code: // Define the user

  • 0

Please find below a snippet of my Node.JS server code:

// Define the user API
var API = {
    list: 'private',
    login: 'public',
    logout: 'private',
    add: 'admin',
    remove: 'admin',
    edit: 'admin'
};

// Attach API handlers
for(var label in API) {
    var denied = 'Permission denied';

    var wrapper = (function (label) {
        return function (req, res) {
            var permission = API[label];

            if(!req.session) {
                if(permission !== 'public') {
                    res.send(denied);
                    return;
                }
            } else if((permission === 'admin') && (req.session.rights !== 'Administrator')) {
                res.send(denied);
                return;
            }

            eval(label + '(req, res)');
        };
    }(label));

    server.post('/user/' + label, wrapper);
}

Basically, I have an API handler for each property in API, and I attach the handlers programmatically, dealing with permissions as appropriate. JSHint however really does not like this. I get three errors:

Line 29: eval(label + '(req, res)');
eval is evil.

Line 31: }(label));
Don't make functions within a loop.

Line 12: for(var label in API) {
The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.

How can this piece of code be improved to make JSHint happy? Are there other changes you would suggest to the code?

  • 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-17T07:42:34+00:00Added an answer on June 17, 2026 at 7:42 am

    I would recommend going through the options that make jslint less strict and setting these ( provided you understand the why ). Jslint is very strict and that is why it has options to make it less strict. The important thing is that you know why they were flagged and why it is OK ok for you to allow these things.

    For example to allow eval use:

    /*jslint evil: true */
    

    Some use:

    /*jslint plusplus: true */
    

    as they find that ++ and — cause them no problems with bug creation or readability.

    jslint is used to bring attention to POTENTIAL pitfalls. If you understand them, you can go around them.

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

Sidebar

Related Questions

Possible Duplicate: Concatenating null strings in Java Please find below the code snippet String
please find below a snippet of code that passes an array, manipulates the array,
Please find below is the sample code:- class ExtendMe{ public void printV(int x){ System.out.println(x);
Please find the relevant snippets of my code below: public static final String GREEK
Please find below entity code, @Entity public class A implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO)
Please find below my ActionResult Index: public ActionResult Index(string SectionText) { var products =
Please find the below code <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml layout=absolute> <mx:Script> <![CDATA[ [Bindable]
Please take a look at the code snippet below. I want the 2nd MongoDB
Please find below the script snippet declare @xml xml set @xml = '<Message> <MessageData>
Please find below code. Map<Long,String> unsortMap = new HashMap<Long,String>(); unsortMap.put(new Long(123), a); unsortMap.put(new Long(123),

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.