Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

6. Classes > Defining Classes

Defining Classes

Defining classes in CoffeeScript can be as simple and as straightforward as one line:

Example: (source: simple_class1.coffee)


class Employee


Example: (source: simple_class1.js)


(function() {
  var Employee;

  Employee = (function() {

    function Employee() {}

    return Employee;

  })();

}).call(this);


With that, we have defined a simple new class called Employee. We can instantiate new instances of that object like so:

Example: (source: simple_class2.coffee)


class Employee

emp1 = new Employee()
emp2 = new Employee()


Example: (source: simple_class2.js)


(function() {
  var Employee, emp1, emp2;

  Employee = (function() {

    function Employee() {}

    return Employee;

  })();

  emp1 = new Employee();

  emp2 = new Employee();

}).call(this);


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint