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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:56:36+00:00 2026-06-04T19:56:36+00:00

class RedGuy constructor : (@name) -> @nameElem = $ @name @nameElem.css color : red

  • 0
 class RedGuy
       constructor : (@name) ->
           @nameElem = $ @name
           @nameElem.css color : red

 class WideRedGuy extends RedGuy
       constructor : ->
           @nameElem.css width : 900

 jeff = new WideRedGuy '#jeff'

I would like #jeff to be both red and wide, but I always get this.name is undefined. How can I extend the constructor (append?) so that I have access to the properties of the original object?

  • 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-04T19:56:37+00:00Added an answer on June 4, 2026 at 7:56 pm

    You need to explicitly call super for this to work. Calling super in WideRedGuy will call RedGuy‘s constructor, after which @nameElem will be properly defined. For a more in-depth explanation, you should consult coffeescript’s documentation on the matter.

    class RedGuy
          constructor : (@name) ->
              @nameElem = $ @name
              @nameElem.css color : red
    
    class WideRedGuy extends RedGuy
          constructor : ->
              ## This line should fix it
              super # This is a lot like calling `RedGuy.apply this, arguments`
              @nameElem.css width : 900
    
    jeff = new WideRedGuy '#jeff'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Class A { string name; IList<A> minorList = new List<A>(); } IList<A> majorList =
class MyClass<T> where T: new() { public Test() { var t = new T();
Class A calls the public method f() in the Constructor. Class B overrides method
class Test extends JPanel implements MouseListener { private JButton b1, b2, b3, b4; public
class Model_Core_NodeContents extends Zend_Db_Table_Abstract { protected $_name = 'node_contents'; protected $_referenceMap = array( Page
Class Account extends CI_Model { private $tbl_rest = array(); private $tbl_fields = array('bs_id', 'bs_name',
class Book(models.Model): name = models.CharField(max_length=127, blank=False) class Author(models.Model): name = models.CharField(max_length=127, blank=False) books =
class GoogleMusicAdapter extends TestFragmentAdapter implements TitleProvider { public GoogleMusicAdapter(FragmentManager fm) { super(fm); } @Override
class Size{ Size(){ } //public final Size SMALL = new Size();//infinite loop final Size
class A { public: int i; }; A *a = new A(); How to

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.