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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:25:23+00:00 2026-06-07T02:25:23+00:00

I am currently looking at coffee-script because the syntax is greate and easier to

  • 0

I am currently looking at coffee-script because the syntax is greate and easier to write/understand than pure javascript. However I found that tutorials using backbone and coffee-script show that the way to create a model is as follows:

class User extends Backbone.Model
  initialize: ->
    alert 'start'

This looks all nice, but when using extends it compiles rather strangely… I understand this is coffee-script’s way of making classes work in javascript.

(function() {
  var User,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

    User = (function(_super) {

    __extends(User, _super);

    function User() {
      return User.__super__.constructor.apply(this, arguments);
    }

    User.prototype.initialize = function() {
      return alert('start');
    };

    return User;

  })(Backbone.Model);

}).call(this);

but if you use:

User = Backbone.Model.extend
    initialize: ->
        alert 'start'

that compiles a lot better (more like how I would write it):

(function() {
  var User;

  User = Backbone.Model.extend({
    initialize: function() {
      return alert('start');
    }
  });

}).call(this);

Can anyone explain to me the differences in the ways of creating a model class and why the first method is used more often in tutorials when the second one compiles more like how I would create a model in pure javascript?

  • 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-07T02:25:24+00:00Added an answer on June 7, 2026 at 2:25 am

    These two methods are functionally equivalent, with no significant difference in how they work. There are some implementation differences, sure, but the end result is the same.

    The real difference, and why you see the larger code generation from the coffeescript extends keyword, is that when you call Backbone.Model.extend, you are calling Backbone’s version of the same code that CoffeeScript produces. It’s encapsulated within Backbone’s extend method, but it’s largely similar in how it works and why.

    The only reason you see the CoffeeScript extends used everywhere, is because you’re looking at CoffeeScript examples. Honestly, that’s it. There’s no benefit to doing it one way or the other. It’s just that CoffeeScript says you should use the extends keyword so people do it that way.

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

Sidebar

Related Questions

Currently looking into learn new technology and silverlight is on the potential list. However,
I am currently looking at creating a script for my site that will count
I am looking for some insight on learning CoffeeScript without learning pure JavaScript. I
I currently looking for a JavaScript (Jquery lib for example) solution to adjust the
I'm currently looking at a copy-on-write set implementation and want to confirm it's thread
I am currently looking to deploy a web forum on the azure platform. I
I am currently looking into a couple of possibilities for a microsite that I
I am currently looking for a way to remove fullstops from a string in
I am currently looking at the C# Metro default controltemplate for scrollbar. And in
I'm currently looking around to find what's allow and what's not in GAE. Using

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.