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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:08:18+00:00 2026-05-27T03:08:18+00:00

Of these alternatives, which is the best style for class-based programming in CoffeeScript? #

  • 0

Of these alternatives, which is the best style for class-based programming in CoffeeScript?

# Alternative 1
class Person
  constructor: (@name, @age) ->

new Person "Peter", 19

# Alternative 2
class Person
  name: ""
  age: 0
  constructor: (@name, @age) ->

new Person "Peter", 19

# Alternative 3
class Person
  constructor: (@name = "", @age = 0) ->

new Person "Peter", 19


# Alternative 4
class Person
  constructor: (name, age) ->
    @name = name ? ""
    @age = age ? 0

new Person "Peter", 19
  • 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-05-27T03:08:19+00:00Added an answer on May 27, 2026 at 3:08 am

    Hmm. #1 is nice and simple. #3 succinctly shows the expected format of the arguments (though the defaults don’t actually make sense—unless you’re expecting a person to be named "", or to be 0 years old).

    What I’d really recommend is using a hash instead:

    class Person
      constructor: ({@name, @age}) ->
    
    new Person(name: "Peter", age: 19)
    

    This frees you from having to memorize the order of the arguments, and makes your instantiation calls more self-documenting.

    (I use this approach in some of the examples in CoffeeScript: Accelerated JavaScript Development.)

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

Sidebar

Related Questions

What are the best practices if you have a class which accepts some parameters
I have been using extplorer http://extplorer.sourceforge.net/ Are there any good alternatives which run on
Are there any alternatives to stat (which is found on most Unix systems) which
Which of theese two alternatives do you find yourself using most often, and which
If I have a greenfield project, what is the best practice Perl based configuration
I'm wondering, which css framework is best suitable for ASP.NET MVC 3? I've tried
I've been asked to choose which is the best option out of three in
Which control would be best for showing a huge (300.000+) list of filenames? I've
Which IDE will suit agile development at its best? When I talk about agile,
Are there alternatives to gitosis that are easier to use? I currently run gitosis

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.