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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:42:00+00:00 2026-05-27T22:42:00+00:00

I have been reading up on Mixins using Coffeescript or just plain Javascript from

  • 0

I have been reading up on Mixins using Coffeescript or just plain Javascript from the following sources:

http://arcturo.github.com/library/coffeescript/03_classes.html (near the bottom)

and

http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/

And while I am able to compile the various examples, I have a major question that seems to be preventing me from making progress in comprehending them.

I have no idea what in the world is going on. To start, I will explain the Coffeescript that is confusing me.

moduleKeywords = ['extended', 'included']

    class Module
      @extend: (obj) ->
        for key, value of obj when key not in moduleKeywords
          @[key] = value

        obj.extended?.apply(@)
        this

      @include: (obj) ->
        for key, value of obj when key not in moduleKeywords
          # Assign properties to the prototype
          @::[key] = value

        obj.included?.apply(@)
        this

A number of questions come up here.

  1. First of all, what are we accomplishing with the moduleKeywords variable? I’m not understanding what that is doing.

  2. Secondly, how does extended?.apply(@) work? What is really going on here? I can look at the JavaScript compilation and see the following code ..

Module.extend = function(obj) {
      var key, value, _ref;
      for (key in obj) {
        value = obj[key];
        if (__indexOf.call(moduleKeywords, key) < 0) {
          this[key] = value;
        }
      }
      if ((_ref = obj.extended) != null) {
        _ref.apply(this);
      }
      return this;
    };

Can anyone shed some general light on this?

From deeper down in The Little Book on Coffeescript, I see an implementation.

ORM = 
  find: (id) ->
  create: (attrs) ->
  extended: ->
    @include
      save: -> 

class User extends Module
  @extend ORM

Here is how I read this:

  • create literal ORM.
  • Declare method find accepting a parameter.
  • Declare method ‘create’ accepting a parameter.
  • Declare method ‘extended’, with sub-method ‘include’, with sub-method ‘save’.

This is where I get the most lost.

The literal ORM has a method, extended, and then Module is implemented/extended by the ‘class’ User. So I take this to mean that User has the same shape as Module. That part makes sense so far, simplistic inheritance. But then I get lost on @extend ORM.

@extend is a method on Module, but what is the extended method doing? When is it called? How is it implemented?

  • 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-27T22:42:00+00:00Added an answer on May 27, 2026 at 10:42 pm
    • extend copies the methods from the “module” object onto the object being extended
    • include copies the methods from the “module” object onto the prototype of the object being extended

    1 The moduleKeywords is used to protect some methods of the module, so the are not copied to object, because they have special meaning

    2 The extended?.apply(@) says that if the module has a property named extended than assume it’s a function and then call this function having the “this” in the function equal to @, @ being the extended object, you can think of it as saying something like (although not quite, but it’s just an intuition) @.extended() (@ == this in coffeescript)

    “apply” function in JS
    the existential operator in CS

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

Sidebar

Related Questions

I have been reading tutorials from several different places like http://css-tricks.com/scrollfollow-sidebar/ or http://jqueryfordesigners.com/fixed-floating-elements/ and
I have been reading about bcrypt (application perspective). Thinking of using it to store
I have been reading about out of memory conditions on Linux, and the following
I have been reading up on web-site performance lately and along side lowering HTTP-Requests
I have been reading about using nHibernate and multiple datasources and I get the
I have been reading about Reliability Features in .NET and have written the following
I have been reading the AVFoundation docs and I have just not been able
I have been reading the JavaScript Scripting Guide for Quicktime and in there it
I have been reading an interesting statement in http://download.oracle.com/javase/tutorial/jdbc/basics/transactions.html The interesting part is: Catching
I have been reading through the C++ FAQ and was curious about the friend

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.