{"action":"closed","issue":{"url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/557","labels_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/557/labels{/name}","comments_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/557/comments","events_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/557/events","html_url":"https://github.com/johnpapa/angular-styleguide/issues/557","id":110644720,"number":557,"title":"Add note for function declaration/ordering when using CoffeeScript","user":{"login":"SimplGy","id":548809,"avatar_url":"https://avatars.githubusercontent.com/u/548809?v=3","gravatar_id":"","url":"https://api.github.com/users/SimplGy","html_url":"https://github.com/SimplGy","followers_url":"https://api.github.com/users/SimplGy/followers","following_url":"https://api.github.com/users/SimplGy/following{/other_user}","gists_url":"https://api.github.com/users/SimplGy/gists{/gist_id}","starred_url":"https://api.github.com/users/SimplGy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimplGy/subscriptions","organizations_url":"https://api.github.com/users/SimplGy/orgs","repos_url":"https://api.github.com/users/SimplGy/repos","events_url":"https://api.github.com/users/SimplGy/events{/privacy}","received_events_url":"https://api.github.com/users/SimplGy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-09T12:07:41Z","updated_at":"2015-10-22T04:13:34Z","closed_at":"2015-10-22T04:13:34Z","body":"Lots of these tips are usefully generic and would apply equally in JS, CoffeeScript, TypeScript. One in particular I can't do it in CoffeeScript, but want to.\r\n\r\nIt's not my intent to start a precompile-or-no dogma discussion, hopefully we can avoid that.\r\n\r\nCoffeescript [doesn't have function declarations](https://github.com/jashkenas/coffeescript/issues/1640). This is not likely to change. Intended to avoid hoisting and unify function definition, It makes [Bindable Members Up Top](https://github.com/johnpapa/angular-styleguide#bindable-members-up-top) difficult to implement.\r\n\r\nThere are a few options. Sometimes we expose all public methods at the bottom in a single hash:\r\n\r\n```coffee\r\n    return api =\r\n      setThis: setThis\r\n      getThat: getThat\r\n```\r\n\r\nThis is ok, but it's at the bottom of the file, so it doesn't have the immediate discoverability of your style :(\r\n\r\nWe also sometimes put everything inside methods and call an `init` at the bottom, again just to handle declaration order.\r\n\r\n```coffee\r\n    vm = this\r\n    init = ->\r\n      vm.getThis = getThis\r\n      vm.setThat = setThat\r\n    getThis = ->\r\n    setThat = ->\r\n    #...\r\n    init()\r\n    return vm # avoid implicit return issues\r\n```\r\n\r\nSo, no particular problem, but I like the style guide and wonder if a note for CS is warranted, and if anyone has some nice ideas on an alternative to hoisted function declarations.\r\n\r\nThanks for reading."}}