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

  • Home
  • SEARCH
  • 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 8399491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:19:10+00:00 2026-06-09T21:19:10+00:00

I am trying to reuse a JavaScript library (sim.js) in CoffeeScript code. In an

  • 0

I am trying to reuse a JavaScript library (sim.js) in CoffeeScript code. In an example that comes with sim.js, there are 3 files, “sim-0.26.js”, “buffet_restaurant.js”, and “buffet_restaurant.html” wired together like this (I’ve eliminated some parameters to simplify):

Inside of “buffet_restaurant.html”, there is

<script type="text/javascript" src="./buffet_restaurant_files/sim-0.26.js"></script>
<script type="text/javascript" src="./buffet_restaurant_files/buffet_restaurant.js"></script>
<script type="text/javascript">
  $(function () {
    $("#run_simulation").click(function () {
      var results = buffetRestaurantSimulation();
...

where buffetRestaurantSimulation is a function inside of buffet_restaurant.js. The code in buffet_restaurant.js starts off like this:

function buffetRestaurantSimulation() 
{
    var sim = new Sim(); 
...

where Sim is defined in sim-0.26.js, like this:

function Sim(){...};

This example runs fine. I want to reuse “Sim” in a CoffeeScript file in node.js. So I try this (invoked from jasmine-node):

sjs = require "./sim-0.26.js"

mysim = new sjs.Sim()

where sim-0.26.js is in the same directory as testsim.spec.coffee, the file containing this code. When I invoke this using:

jasmine-node --coffee ./testsim.spec.coffee

I get this:

mysim = new sjs.Sim();
        ^
TypeError: undefined is not a function

I suspect I am doing a ton of things wrong. I’m pretty new to all this.

Any ideas?

  • 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-09T21:19:11+00:00Added an answer on June 9, 2026 at 9:19 pm

    Unless Sim is added to exports it will not be available when required – see the docs on modules for more information on the way Node.js modules need to be written.

    If this needs to work in both the browser and in node, then simply add this to the code for sim.js:

    var root = typeof exports === "object" ? exports : window;
    
    root.Sim = Sim;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some constants in JavaScript that I'd like to reuse in several files
Im trying to reuse a code that i've made for toggleswitch on my application
I am trying to reuse a piece of jQuery code accordion code that I
I am trying to maximize the reuse of some code. On my custom javascript
I am trying to reuse shape data to dynamically create new shapes in code.
I'm trying to reuse a small chunk of code inside a custom button class.
I'm trying to store a reference of an HTML tag for later reuse. e.g.
I am trying to reuse code from another project, but while copying the classes
I am trying to reuse a framelayout that has an image and textview inside
I'm trying to store an array value so that I can reuse when Sub

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.