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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:16:28+00:00 2026-06-06T06:16:28+00:00

In JavaScript I’d set up a class like: var SomeClass = (function() { var

  • 0

In JavaScript I’d set up a class like:

var SomeClass = (function()
{
    var _this   = { };
    var privateVar = 'foo'

    _this.publicVar = 'bar'

    function privateFunction()
    {
        return privateVar;
    }

    _this.publicFunction = function()
    {
        return _this.publicVar;
    }

    return _this;
})();

This is fine as in privateFunction I can reference publicFunction by either calling SomeClass.publicFunction() or _this.publicFunction()

Now in Coffeescript I’m trying to set up my class so that I can call class functions, how do I go about this? How can I create a class in coffeescript called Foo and get a function in the class to reference another function in that class?

  • 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-06T06:16:29+00:00Added an answer on June 6, 2026 at 6:16 am

    Your question is confusing.

    If you want to create a class method, you could do it like

    class Foo
      constructor: ->        
    
      m1: ->
        Foo.classMethod()
    
      m2: ->
        @privateMethod()
        @m1()
    
    Foo.classMethod = ->
    

    note the last line. A class method is one that lives on the function that defines the class.

    If you want to call a method from another method, its no big deal. m1 and m2 in this example demonstrate this. Note that each invocation is scoped to this, which is the current instance of your class Foo. So you could do

    f = new Foo()
    f.m2()
    

    which would create a new instance of Foo, and then invoke m2 on that instance. m2 in turn invokes the class method classMethod.

    Check this out to see the javascript to which the above coffeescript compiles.

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

Sidebar

Related Questions

JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;
Javascript Code YAHOO.util.Event.onDOMReady(function (ev) { var carousel = new YAHOO.widget.Carousel(container, {isCircular: true, numVisible:1}); console.log(carousel.set('navigation',
Javascript: var images = $('#slideshow').children(); var dot_holder = $('#slider_dots'); /* Create the dots*/ images.each(function(index,item){
Javascript functions can be declared on a objects prototype like this: <object name>.prototype.<variable name>=function(){
Javascript has built-in function for time where var date = new Date(); d.getHours() //gets
Javascript Code var d = function c() { console.log(c); }; d(); // function c()
JavaScript is purported to have first-class functions, so this seems like the following ought
Javascript function does not work when function loadcontents(obj) { var params = $(obj).attr('href').split('?'); $.getJSON(IVIDPLAY_BASE_DIR+'content/load2.php?'+params[1],
JavaScript (JQuery) $('input').keyup(function(e) { var code = e.keyCode ? e.keyCode : e.which; switch(code) {
Javascript: $(document).ready(function() { $('#field').keyup(function() { var count = '??'; $('#count').html(count); }); }); HTML: <input

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.