P
P
Partizanin2017-11-27 03:46:07
JavaScript
Partizanin, 2017-11-27 03:46:07

How to write named function in coffeeScript?

Tell me what's wrong when I try to write a regular named function in coffeeScript and compile it with gulp and I don't get exactly what I need
. Sources and examples

CoffeeScript source
app = angular.module "myApp2", []

app.controller("myController", ($scope, $http, $q)->

  init () -> console.log "hello coffee"

)
The result of compiling coffeeScript
var app;

app = angular.module("myApp2", []);

app.controller("myController", function($scope, $http, $q) {
  return init(function() {
    return console.log("hello coffee");
  });
});
Here's what should happen
var app = angular.module("myApp2", []);

app.controller("myController", function ($scope, $http, $q) {

    function init() {
      console.log("hello coffee");
       }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2017-11-27
@Taraflex

Will not work. The closest analogue

app = angular.module "myApp2", []

app.controller "myController", ($scope, $http, $q)->
  init = -> 
    console.log "hello coffee"; 
    return
  return

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question