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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:51:51+00:00 2026-06-04T18:51:51+00:00

coffee -generated JS of the following simple code snippet: console.log ‘b’ if ‘b’ in

  • 0

coffee-generated JS of the following simple code snippet:

console.log 'b' if 'b' in arr

is

var __indexOf = [].indexOf || function(item) {
    for (var i = 0, l = this.length; i < l; i++) {
        if (i in this && this[i] === item) return i;
    } return -1;
};

if (__indexOf.call(arr, 'b') >= 0) {
  console.log('b');
}

I can understand why it is so. IE doesn’t support indexOf, and we want to make sure our CS code runs smoothly on all browsers. But, when writing the code for a Node.js server, we know exactly what the JS engine supports (ECMA-262, 5th edition), so we wouldn’t need the above trick.

I’m not terribly familiar with different JavaScript implementations, but I’m sure it’s not the only non-optimal code coffee -c produces because of browser incompatibilities, and if we consider all of them in a production server with thousands of concurrent connections, they add a considerable unnecessary overhead to the code.

Is there a way to remedy this? More and more Node.js code is written in CS these days, and with SourceMap on the horizon, the number would be even greater…

  • 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-04T18:51:52+00:00Added an answer on June 4, 2026 at 6:51 pm

    This is barely non-optimal; the __indexOf declaration is evaluated once, at the beginning, and it’s immediately resolved to [].indexOf, i.e. using the underlying implementation’s Array.prototype.indexOf. That’s not exactly a huge expense, surely.

    I’d need to see some other examples of “non-optimal” code, but I’m sure most of them fall into the same basket. Number of concurrent connections doesn’t scale the effect of this at all.

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

Sidebar

Related Questions

From the following code: <ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol> How do I create an
(coffee break) THE ANIMATION IN QUESTION Having this: $('.cloud').each(function(){ var cloud = $(this); function
I wrote some JQuery code in an .js.coffee file and I get the following
the code in my app.coffee it uses coffee script i have put body parser
I was looking through some compiled coffee-script code, and I noticed something like the
In Brad's CorePlot I've seen this snippet, which eliminated the need for some coffee.
I have some code written in CoffeeScript and I want to optimize the generated
I am at a loss this morning. Maybe my coffee was drugged? Simple problem-
Just saw some interesting code while doing a typo in coffee-script. I got the
No coffee. Brain. Not. Functioning. I have this linq query here: Public Function ListAllVisitDates()

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.