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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:48:51+00:00 2026-06-03T17:48:51+00:00

Hi everyone: I am trying to create a namespace so I can use a

  • 0

Hi everyone: I am trying to create a namespace so I can use a class in different coffeescript files throughout my application (at least that is my understanding of what you use a namespace for)

I found a very good example here: Classes within Coffeescript 'Namespace'

excerpt:

    namespace "Project.Something", (exports) ->
      exports.MyFirstClass = MyFirstClass
      exports.MySecondClass = MySecondClass

However, when I implement this, I am getting: namespace is not defined in my console.

My namespace is implemented exactly how it looks in the example above. It seems that my namespace definition is just not being recognized by coffeescript somehow.

any ideas? could there be a versioning issue here or something?

thanks in advance!!!

  • 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-03T17:48:53+00:00Added an answer on June 3, 2026 at 5:48 pm

    The namespace function from that question:

    namespace = (target, name, block) ->
      [target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
      top    = target
      target = target[item] or= {} for item in name.split '.'
      block target, top
    

    isn’t part of CoffeeScript, you have to define that helper yourself. Presumably you don’t want to repeat it in every file so you’d have a namespace.coffee file (or util.coffee or …) that contains the namespace definition. But then you’re left with the problem of getting your namespace function into the global namespace. You could do it by hand:

    namespace = (target, name, block) ->
      [target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
      top    = target
      target = target[item] or= {} for item in name.split '.'
      block target, top
    
    (exports ? @).namespace = namespace
    # or just (exports ? @).namespace = (target, name, block) -> #...
    

    Demo: http://jsfiddle.net/ambiguous/Uv646/

    Or you could get funky and use namespace to put itself into the global scope:

    namespace = (target, name, block) -> #...
    namespace '', (exports, root) -> root.namespace = namespace
    

    Demo: http://jsfiddle.net/ambiguous/3dkXa/

    Once you’ve done one of those, your namespace function should be available everywhere.

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

Sidebar

Related Questions

I'm trying to create a web application project template for everyone to use here
I'm trying to create a global (singleton) class that can associate any type of
hello everyone im trying to create this tweak that copies a file from one
everyone. I am trying to create a database in which I can store pictures
I'm trying to create an application that will display all restaurants within the users
I use XAMPP on Leopard. I'm trying to create cache files using fopen but
(source: flickr.com ) Hi again everyone :) So today I'm trying to basically create
Right, I'm trying to create a system where by the user can do something,
Thanks everyone for the feedback Hi All, I'm am trying to create a stored
I am trying to create a child that calls sort. The parent sends data

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.