angularjs - Angular Coffeescript to Javascript conversion - next function is considered as the body of the previous function -


i having strange issue @ times when using coffeescript. example below:

coffeescript:

$scope.function1 = () -> console.log("function 1")

$scope.function2 = () -> console.log("function 2")

javascript:

$scope.function1 = function() { console.log("function 1"); return $scope.function2 = function () { console.log("function 1"); }

why second function goes inside first one? highly appreciated. not happening time though.

in coffeescript, indentation meaningful. code posted in question translates want. if second function indented relative first:

$scope.function1 = () ->   console.log("function 1")    $scope.function2 = () ->     console.log("function 2") 

...it translates incorrectly in way you've shown.

be sure consistent in use of spaces or tabs.

but again, quoted in question, it's fine:

$scope.function1 = () ->     console.log("function 1")  $scope.function2 = () ->     console.log("function 2") 

becomes

$scope.function1 = function() {   return console.log("function 1"); };  $scope.function2 = function() {   return console.log("function 2"); }; 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -