class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
class Animal name: "animal" move: (meters) -> alert (@name + " moved " + meters + "m." ) class Snake extends Animal constructor: (name) -> @name: name move: -> alert ( "Slithering..." ) super ( 5 ) class Horse extends Animal constructor: (name) -> @name: name move: -> alert ( "Galloping..." ) super ( 45 ) sam: new Snake ( "Sammy the Python" ) tom: new Horse ( "Tommy the Palomino" ) sam.move() tom.move()
- ( function () {
- var Animal, Horse, Snake, sam, tom;
- var __extends = function (child, parent) {
- var ctor = function () {};
- ctor.prototype = parent.prototype;
- child .__ superClass__ = parent.prototype;
- child.prototype = new ctor ();
- child.prototype.constructor = child;
- };
- Animal = function () {};
- Animal.prototype.move = function (meters) {
- return alert ( this .name + "moved" + meters + "m." );
- };
- Snake = function (name) {
- this .name = name;
- return this ;
- };
- __extends (Snake, Animal);
- Snake.prototype.move = function () {
- alert ( "Slithering ..." );
- return Snake .__ superClass __. move.call ( this , 5 );
- };
- Horse = function (name) {
- this .name = name;
- return this ;
- };
- __extends (Horse, Animal);
- Horse.prototype.move = function () {
- alert ( "Galloping ..." );
- return Horse .__ superClass __. move.call ( this , 45 );
- };
- sam = new Snake ( "Sammy the Python" );
- tom = new Horse ( "Tommy the Palomino" );
- sam.move ();
- tom.move ();
- }) ();
- class Data
- manyData: null
- constructor: ->
- deferred: new Deferred ()
- @initData (deferred)
- SomeClass.fillData (deferred)
- initData: (deferred) ->
- deferred.addCallback: (data) =>
- @manyData: data
- deferred.addCallback: (error) ->
- alert (error.name + ":" + error.message)
- new Data ()
- var Data;
- Data = function () {
- var deferred;
- deferred = new Deferred ();
- this .initData (deferred);
- SomeClass.fillData (deferred);
- return this ;
- };
- Data.prototype.manyData = null ;
- Data.prototype.initData = function (deferred) {
- deferred.addCallback = ( function (__this) {
- var __func = function (data) {
- this .manyData = data;
- return this .manyData;
- };
- return ( function () {
- return __func.apply (__ this, arguments);
- });
- }) ( this );
- deferred.addCallback = function (error) {
- return alert (error.name + ":" + error.message);
- };
- return deferred.addCallback;
- };
- new Data ();
var
, and forget about the word function
- they are forbidden in CoffeeScript. But if you need to embed plain javascript into your CoffeeScript sources, simply wrap them in ` `
characters:
- hi: `function () {
- return [document.title, "Hello JavaScript" ] .join ( ":" );
- } `
- `var getSomeValue = function () {...}`
- var hi;
- hi = function () {
- return [document.title, "Hello JavaScript" ] .join ( ":" );
- };
- var getSomeValue = function () {...};
- cholesterol: 127
- healthy: 200 > cholesterol> 60
- var cholesterol, healthy;
- cholesterol = 127 ;
- healthy = ( 200 > cholesterol) && (cholesterol> 60 );
- theBait: 1000
- theSwitch: 0
- [theBait, theSwitch]: [theSwitch, theBait]
- var _a, theBait, theSwitch;
- theBait = 1000 ;
- theSwitch = 0 ;
- _a = [theSwitch, theBait];
- theBait = _a [ 0 ];
- theSwitch = _a [ 1 ];
- numbers: [ 0 .. 9 ]
- threeToSix: numbers [ 3 .. 6 ]
- copy: numbers [ 0 ... numbers.length]
- var copy, numbers, threeToSix;
- numbers = ( function () {
- a = []; for ( var i = 0 ; ( 0 <= 9 ? i <= 9 : i> = 9 ); ( 0 <= 9 ? i + = 1 : i - = 1 )) a.push (i);
- return a;
- }). call ( this );
- threeToSix = numbers.slice ( 3 , 6 + 1 );
- copy = numbers.slice ( 0 , numbers.length);
- yearsOld: {max: 10 , ida: 9 , tim: 11 }
- ages: for child, age of yearsOld
- child + "is" + age
- var _a, _b, age, ages, child, yearsOld;
- var __hasProp = Object.prototype.hasOwnProperty;
- yearsOld = {
- max: 10 ,
- ida: 9 ,
- tim: 11
- };
- ages = ( function () {
- _a = []; _b = yearsOld;
- for (child in _b) { if (__hasProp.call (_b, child)) {
- age = _b [child];
- _a.push (child + "is" + age);
- }}
- return _a;
- }) ();
- years: [ 2000 .. 2010 ]
- for year in years
- "year is" + year
- var _a, _b, _c, year, years;
- years = ( function () {
- a = []; for ( var i = 2000 ; ( 2000 <= 2010 ? i <= 2010 : i> = 2010 ); ( 2000 <= 2010 ? i + = 1 : i - = 1 )) a.push (i);
- return a;
- }). call ( this );
- _b = years;
- for (_a = 0 , _c = _b.length; _a <_c; _a ++) {
- year = _b [_a];
- "year is" + year;
- }
Source: https://habr.com/ru/post/97993/