Coffeescript: Reference class method from instance method without hardcoding

Taking the following code as example:

class MyClass

  @staticMethod: -> hello_world()

  instanceMethod: -> MyClass.staticMethod()

Is there a way I could reference MyClass from inside instanceMethod without explicitly naming it? something like self.staticMethod()

JS CoffeeScript – Same random number from method

I’ve created a class in coffeescript with a randomInt method that generates x and y instance variables. However when I create objects from this class the x and y values are the different but consisten

Calling class method from instance method in objective c

What is the safe and correct way of calling a class method from an instance method in objective – C ?

Calling a class method from an instance method [closed]

I want to call a class method from an instance method to use its return value. This is my class method +(double) minFMFrequency { return 88.3; } and this is my instance method -(void) chackFrequency

Ruby: Calling class method from instance

In Ruby, how do you call a class method from one of that class’s instances? Say I have class Truck def self.default_make # Class method. mac end def initialize # Instance method. Truck.default_make

Accessing class method from an instance method

Say I have the following code class Monster def self.yell ‘i am yelling!’ end def shout_something Monster.yell end end My yell method is a class method while shout_something is an instance method tha

Invoke a c++ class method without a class instance?

Is it possible to invoke a c++ class method without first creating a class instance? Suppose we have the following code: // just an example #include <iostream> using namespace std; class MyClass

Calling a method of a Ruby Singleton without the reference of ‘instance’

I would like to call a method of a Singleton Object without the reference to its instance SingletonKlass.my_method instead of SingletonKlass.instance.my_method i’ve came up with this solution (using

How to call a class method without creating an instance

In Java you can call a class method without creating a variable with the instance of the class and still call that class method: new Database().GetSomeValuesOutOfSomeTableJava(); If I try the same wi

Coffeescript: dynamically create instance of the class a method is called on

I am building a Node.js application using object oriented coffeescript. I have a super class with a static method like: class RedisObject @find: (id, cb) -> client.HGETALL #{@className()}|#{id},

Calling protected class method from instance method in Ruby

I’ve been having this bothering recurring theme; let’s just say, I have a class which defines an instance method and a protected class method. The instance method must call the class method. In order

Answers

You can use constructor to get at the “class” just like in JavaScript:

instanceMethod: ->
    @constructor.staticMethod()

Demo (with added subclassing for good measure): http://jsfiddle.net/ambiguous/zM3ND/